use strict; $_="this that other thing that thw tests sometimes"; my $regex = qr/(t..)\w+\s+?(\w\w)(.+)/; my @buffer; my @x; while ( (@x[0..1],$_) = /$regex/) { push @buffer, [ @x ]; print join(",",@x) . ";\n"; }