

sub utf8substr {
    my($utf8str, $offset, $length) = @_;
    
    no utf8;
    $utf8str =~ m/^(?: [\x01-\x7f] | [\xc0-\xdf][\x80-\xbf] | [\xe0-\xef][\x80-\xbf][\x80-\xbf]){$offset}
    (([\x01-\x7f] | [\xc0-\xdf][\x80-\xbf] | [\xe0-\xef][\x80-\xbf][\x80-\xbf]){$length})/x;
    use utf8;

    return $1;
}


sub utf8length {
    my($utf8str) = @_;
    
    no utf8;
    my(@utf8chars) = ($utf8str =~ m/^([\x01-\x7f] | [\xc0-\xdf][\x80-\xbf] | [\xe0-\xef][\x80-\xbf][\x80-\xbf])*$/x);
    use utf8;

    return scalar(@utf8chars);
}



