foreach my $current (@current) { foreach my $base (@base) { if ($base =~ /^\Q$current\E/) { # ... } } }