in reply to Portable string length in bytes

unpack with "b*" could be a solution:
use strict; my $a = "1234".chr(4000)."abcd"; { use bytes; print length($a), "\n"; #11 bytes } print length($a), "\n"; #9 chars print length(unpack("b*", $a)) / 8; # 11 bytes
I tried with 5.8 seems fine. However, I leave two things open:
  1. whether unpack b* is supported in your old versions? (I cannot test, as I don't have those old versions)
  2. for long strings, I guess performance would be an issue.