http://www.perlmonks.org?node_id=738608


in reply to Re^3: Counting number of characters in a string
in thread Counting number of characters in a string

Remove the backslash, add the "s" modifier. And the parens aren't necessary.

my $cnt = @{[$str =~ /./sg]};

Cheaper alternative:

my $cnt =()= $str =~ /./sg;