in reply to Stack table columns with hash of arrays

Another solution for you.
#!/usr/bin/perl -w use strict; my @RowNames; my @Columns; while (<DATA>) { my $i=0; my ($name, @row)= split; push @RowNames, $name; push @{$Columns[$i++]}, $_ for (@row); } foreach my $cref (@Columns) { foreach my $name (@RowNames) { print "$name\t",shift @$cref,"\n"; } } =prints foo1 1 foo2 2 foo3 3 foo1 4 foo2 5 foo3 6 foo1 7 foo2 8 foo3 9 =cut __DATA__ foo1 1 4 7 foo2 2 5 8 foo3 3 6 9