in reply to Dividing a file into groups of two words and counting them

You could modify your loop as follows:
foreach my $sequence (@bigram) { #my $count; is this a bug? my @word = split ' ', $sequence; my $prev = shift @word; foreach $word (@word) { $count{"${prev}_${word}"}++; $prev = $word; } }

If "test.txt" contains:

a b n z d f n z v

this prints:

n_z occurs 2 times a_b occurs 1 times d_f occurs 1 times f_n occurs 1 times b_n occurs 1 times

Is this what you are looking for?

Note that my $count; seems to be a bug.

Update: Another solution would be to try to use List::MoreUtils qw(natatime);