use strict; use warnings; my $X = @ARGV ? shift : 2; my %array = ( Key_One => [qw / 50 25 100 90/], Key_Two => [qw / 35 18 110 72/], Key_Three => [qw /100 35 99 82/], ); my @names = qw /One Two Three Four/; for (my $i = 0; $i < @names; $i ++) { my @keys = sort {$array {$b} [$i] <=> $array {$a} [$i]} keys %array; print "Column $names[$i]\n"; foreach my $key (@keys [0 .. $X - 1]) { printf "%10s = %3d\n" => $key, $array {$key} [$i] } } __END__ Column One Key_Three = 100 Key_One = 50 Column Two Key_Three = 35 Key_One = 25 Column Three Key_Two = 110 Key_One = 100 Column Four Key_One = 90 Key_Three = 82