chomp (@ID); foreach $ID(@ID){ foreach $file(@files){ print "$file" if ($file =~ /($ID)/); } }