in reply to if or switch?

With Perl 5.10, you can do this:
use strict; use feature qw(switch say); use warnings; foreach my $str (qw/fookey1 barkey2 bazkey3/) { given ($str) { when (/key1/) { say 'matched key1'; } when (/key2/) { say 'matched key2'; } when (/key3/) { say 'matched key3'; } } }
See the docs for Switch statements.