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

Here's a hint... suppose you could read in one word at a time. Then you could use a strategy like this:
my $last_word; sub process_word { my $word = shift; ...process it... $last_word = $word; } for every word in the file { process_word($word); }
Now we just need a way to read every word in the file and sent it through the process_word routine. As a first step, why don't you write the code assuming that there is only one word per input line and get that working. Then see what you have to do to modify it when there are multiple words on an input line.