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

while ($x =~ m/%(.)/g) { push(@order, $1); $count{$1}++; }
At the end of the while loop, @order contains the order in which the %-codes were found, and %count contains the counts.