for my $i (0 .. $COLS-1) { push @OUT, @IN[map {$_*$COLS+$i} 0..($#IN/$COLS)]; }