if (m/key(\d)/) { # $1 contains the digit following "key" print "Found key followed by a $1\n" $count{$1}++; print "Total times this key was seen: ", $count{$1}, "\n"; ... }