#!/usr/bin/perl -w use strict; # transpose input. won't align right if rows don't have # same # num of things, but then again Op's version will go # pretty wacky with: 1 2 3 4 # a b c d e f my @inAoA; my @transposed_AoA; while () { chomp; #not needed for \s, but here for \t option push(@inAoA,[split(/\s/,$_)]); #could be \t too } transpose_2d_array(\@inAoA, \@transposed_AoA); dump_AoA (\@transposed_AoA); sub transpose_2d_array { my ($in_aref, $out_aref) = @_; foreach my $in_row (@$in_aref) { my $new_row =0; foreach my $col_ele (@$in_row) { push (@{$out_aref->[$new_row]},$col_ele); $new_row++; } } } sub dump_AoA #with tabs between columns { my $AoA_ref = shift; foreach my $aref (@$AoA_ref) { print join("\t",@$aref),"\n"; } } =PrintOut of above code: 1 a 2 b 3 c 4 d 5 e 6 f =cut __DATA__ 1 2 3 4 5 6 a b c d e f