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

Rather than constructing @word for each line, construct it for the entire file. Then rather than
foreach $word(@word) { $count{$word}++; }
you could say
for $w (0 .. $#word) { $count{$word[$w].' '.$word[$w+1] }++; }

Beware of having an odd number of words in the file; you might pretest and stick a blank in the final (even) entry.

The code hasn't been tested, but I hope you get the idea.