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