# Get an arbitrary top level key and use it to # create an ordered array of the sub hash keys my $anyKey = keys %{ $hashref1 }; my @sortedKeys = sort keys %{ $hashref1->{ $anyKey } }; for my $id ( sort keys %{ $hashref1 } ) { # extract an array of *ordered* results for this key from each hash my @results1 = @{ $hashref1->{ $id } }{ @sortedKeys }; my @results2 = @{ $hashref2->{ $id } }{ @sortedKeys }; my @results3 = @{ $hashref3->{ $id } }{ @sortedKeys }; ## join them together with spaces ## and print them along with the key printf "%14s : \t%s\n\t\t%s\n\t\t%s\n\t\t%s\n", $id, join( ' ', @sortedKeys ), join( ' ', @results1 ), join( ' ', @results2 ), join( ' ', @results3 ); }