in reply to Extracting the number of %'s in a string

Should "%%a" count as one (x=%) or two (x=%,x=a)? The solution below returns the former.

my $count = my @order = $string =~ /%(.)/sg;

Or if you want the count for each different "x" instead of one global count:

$count{$_}++ for my @order = $string =~ /%(.)/sg;

Update: Added second solution.