my %histogram; my @wordstofind = qw( a am an and are as at be been but by can co de do due each ); while () { my @currentline = split; $histogram{$_}++ for @currentline; } foreach my $i (@wordstofind) { while ( my ($key, $value) = each (%histogram) ) { if ($key =~ /\b$i\b/) { print "Found $key, $value times\n"; } } } __DATA__ hello, I am an elephant. I have a long trunk. #### Found a, 1 times Found am, 1 times Found an, 1 times