use strict; use warnings; my %matches = map {$_ => 0} qw(january february egypt); while () { chomp; ++$matches{$_} if exists $matches{$_}; } for my $word (sort keys %matches) { if (! $matches{$word}) { print "Didn't find $word.\n"; } elsif (1 == $matches{$word}) { print "Found $word once.\n"; } else { print "Found $word $matches{$word} times.\n"; } } __DATA__ january february january moon saturday #### Didn't find egypt. Found february once. Found january 2 times.