in reply to Word Pairs and Lines

How about something like:

my ($word1, $word2) = split(/\s+/); if defined($word2) { ... }

instead of:

foreach $word (split /\s+/) { ... }

In other words, don't loop over every word. Get the first two words of every line, and work with those.