in reply to global regex

Several things.
  1. $2 and $3 are not populated by simply using /g
  2. You're not testing for matches
  3. Your __DATA__ section reflects a "log file" which has precisely 3 words per line. Note what happens to line 3 of my __DATA__.
#!/usr/bin/perl use strict; use warnings; # 778252 while(<DATA>) { if ( $_ =~ /(\w+\s*)(\w+\s*)(\w+\s*)/ ) { print "$1 $2 $3"; } } __DATA__ word1 word2 word3 word4 word5 word6 7word 12345 8word *@- 9word

Output:
word1 word2 word3
word4 word5 word6
7word 12345 8word