in reply to
The “real length" of UTF8 strings
length returns the number of characters. To get the length in bytes, you have to convert the string into a given encoding:
my $s="\x{5fcd}\x{65e0}\x{53ef}\x{5fcd}";
use Encode;
print length encode("utf8", $s), "\n"; # 12
Since Unicode strings are stored in utf8 internally, you can use a number of hacks to avoid the explicit re-encoding:
print do {use bytes; length($s)}, "\n"; # 12 (see perldoc -f length)
# or
utf8::encode($s); # resets the utf8 flag
print length($s), "\n"; # 12