in reply to if or switch?

What are your actions for each of the three cases?

If they are very different, then a dispatch table or a Perl6 switch statement is about the most efficient.

If the code for all three cases is very similar, then perhaps this can be made to work for you:

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"; ... }