http://www.perlmonks.org?node_id=763851

cosmicperl has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,
  I've been reviewing an old script I wrote that extracts groups of words. The current code I have for getting words in pairs is:-
my $text = "hello to all the perl monks"; while ($text =~ /\b([A-Za-z'\-]+ [A-Za-z'\-]+)\b/g) { print "$1\n"; }#while
I've just found a bug as this isn't doing what I expected. I thought the output would be:-
hello to to all all the the perl perl monks
But the output is actually:-
hello to all the perl monks
I was about to just run the regexp twice, removing the first word, but this seemed like a nasty fix. I'm guessing there is a better way to get the result I want?

Thanks in advance

Lyle