my $r2; my $flipper = 0; for( @$r ) { if( $flipper++ % 2 ) { push @{$r2->[$#{$r2}]}, $_; } else { push @$r2, [ $_ ]; } }