hashbang, strict, warn, etc... my $regex1 = qr/foo\d+/; my $regex2 = qr/bar\S+?/; my @string = qw(foo17 barABC this-has-no-match); for my $string(@string) { if ($string =~ m/($regex1)/) { say "matched part of \"$string\" is $1 when regex is \"$regex1\""; next; } elsif ( $string=~ m/($regex2)/ ) { say "matched part of \"$string\" is $1 when regex is \"$regex2\""; next; } else { say "no match on $string"; } }