# for loop for my $i (0 .. $#a1) { for my $j (0 .. $#a2) { push @indices, $i if $a2[$j] eq $a1[$i]; } }