my @files = (.....some file names...); my %hash = (....keyed upon file names...); my @newfiles; foreach my $file (@files) { push (@newfiles, $file) unless ( grep{/\Q$file\E/}keys %hash ); # pushes the name of $file to @newfiles if no match # is found to the pattern within keys of %hash. }