http://www.perlmonks.org?node_id=635084


in reply to regular expressions and nested loops

I don't see any fundamental problems here except one: in your outer loop you're iterating over the size of the array @car, when logically it seems that you want to iterate over @make. To reduce your confusion, you can just use foreach-style loops for both:
foreach my $make (@make) { foreach my $car(@car) { if ($make =~ /$car/) { push (@shop, $make); print cftr2dmatch2 "@shop"; } } }
I also removed the calls to next which you don't need because the foreach loop will take care of that for you. Also, if cftr2dmatch2 is a function, make sure it is defined in your code at some earlier point, otherwise it will be treated as a filehandle. To avoid this problem say  print cftr2dmatch2("@shop"); instead. Also be sure to add use warnings; at the top of your code.