foreach $element (@a) { foreach $number (@b) { if ($element =~ /\D$number\D/) { push (@c, $element); } } }