# foreach group of n words in array @n_words my $nth_word = pop @n_words; $hash{join ' ', @n_words}{$nth_word}++;