$ cat t.pl #!/usr/bin/perl use strict; use warnings; my %H = (a=>1, d=>2); while () { s/\s+$//; if (exists $H{$_}) { print "$_ exists in hash\n"; } else { print "$_ missing from hash\n"; } } __DATA__ a b c d