use warnings; use strict; use Text::ExtractWords; my $text = do {local $/; }; # Slurp the text my @words; my %hash; words_list (\@words, $text); while (@words) { ++$hash{$_ = shift @words}; ++$hash{"$_ $words[0]"} if exists $words[0]; ++$hash{"$_ $words[0] $words[1]"} if exists $words[1]; } print "$_: $hash{$_}\n" for sort keys %hash; __DATA__ Three blind mice. Three blind mice. See how they run. See how they run. The butcher's wife came after them with a knife, three blind mice.