Remove the backslash, add the "s" modifier. And the parens aren't necessary.
my $cnt = @{[$str =~ /./sg]};
Cheaper alternative:
my $cnt =()= $str =~ /./sg;
In reply to Re^4: Counting number of characters in a string
by ikegami
in thread Counting number of characters in a string
by jeffpflueger
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |