while(){ if (/$pattern/ox) #options to allow whitespace in the pattern, and to prevent the compiler from recalculating it at every run) $chars{$&}++; #$& is the part of the string that actually matches the pattern } foreach (keys %chars){ print "unpack 'U*', $_ matched $chars{$_} times.\n"; #I am unsure on the "unpack"