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; } } #### a b n z d f n z v #### 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