my ( @even, @odd ); while ( $text =~ /\G ( [^,]+ ) (?: , ( [^,]+ ) )? (?: , | \z ) /gx ) { push @even, $1; push @odd, $2 if defined $2; }