#!/usr/bin/perl use strict; use warnings; my %hash_name = ( "one" => 1, "two" => 2, "three" => 3, "four" => 4 ); open MYFILE, ('/me/out.txt'); foreach my $line (){ next if grep {$_ !~ keys %hash_name} $line; # above line seems to work but how do I find the hash key that matched? # OR is there a better way to do this altogether? } close(MYFILE);