vroom has asked for the wisdom of the Perl Monks concerning the following question:
How do I find the length of a string?
Originally posted as a Categorized Question.
$foo = "quux";
$foolen = length $foo; # in this case, 4
Since Perl 5.6, Perl has had Unicode support, which manifests itself as UTF-8 encoded strings. If you want to find out how many characters a string has, simply use length($string). It just works.
However, if, for some reason, you need to find out how many bytes a string uses (which may be different from how many UTF-8 characters the string has):
my $len = bytes::length($string);
Unless you know what you are doing, better steer clear of the latter. Use the former. (See perlunicode for more information.)