while () { my @accum; my $ate_the_whole_thing = 0; while (/\G$item_regex/g) { push @accum, [$1, $2, $3]; $ate_the_whole_thing = (pos() == length); } if ($ate_the_whole_thing) { print join ',', @$_, "\n" for @accum; } } #### while () { my @accum; push @accum, [$1, $2, $3] while (/\G$item_regex(?=$item_regex*\Z)/g); print join ',', @$_, "\n" for @accum; }