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