It's really a double loop.
#!/usr/bin/perl
# http://perlmonks.org/?node_id=1128809
use strict;
use warnings;
while(<DATA>)
{
my @items;
s/\s+/ /g; # simplify
push @items, $1 =~ /, *(\w+)/g while /\btest \w+((?:, *\w+(?: is \w+
+)?)+)/g;
@items and print "FOUND: @items\n";
}
__DATA__
this line has nothing, nothing, nothing...
1 , 2, 3, 4 is four, 5, 6 test 00,11 is one,22, 33 is three,44,55 is
+ the best, and this is not a test 111, 222, 333 as random words to
+ finish
this should be a test, but nothing must be returned 4444, 7777, 9999 i
+s garbage