foreach $G (@array1){ for $x (0..$#array2){ if($array2[$x] =~ /$G/){ push(@Coordinates,"$array2[$x]"); } } }