use strict; use warnings; my @midWords = qw(stop start finish); my %sentences = ( 1 => "Start starts the start sentence.", 2 => "This is a sentence in the middle.", 3 => "This is not the start or the finish, nor even a good place to stop.", 4 => "This is the finish and a good place to stop." ); my %testWords; @testWords{@midWords} = (0); foreach my $sentence (values %sentences){ for (split /\W/, $sentence) { ++$testWords{lc $_} if exists $testWords{lc $_}; } } print join "\n", map {"$_ => $testWords{$_}"} sort keys %testWords;