foreach my $teststring ( @strings ) { print( "---$teststring---\n" ); foreach my $testnum ( sort { $a <=> $b } keys %test ) { if ( $teststring =~ m/$test{$testnum}/ ) { print( "test $testnum matches\n" ); } else { print( "test $testnum does not match\n" ); } } }