use strict; foreach (@files){ my $name2; if(($name2) = / ^cqa_ # Starts with cqa_ (.*) # Here's the namestring we want \.output # and the right file extenstion $/xi # and nothing else. and $ModNameList =~ /$name2/){ print "FOUND: $name2\n"}}