for $i(0.. $#array1){ for $j(0.. $#array2){ if($array2[$j]=~ /$array1[$i]/){ print"$array1[$j] belongs to $array2[$i]"; last; }}}