in reply to How to count the number of chars in a string
my $count = () = /\d/g;
If you need to count the characters in a tight loop, note that tr is faster than regex match:
my $count = tr/0-9//;
Hashes are usually used when you're interested in frequencies of the individual characters.
my %freq; ++$freq{$_} for split //;
|
|---|