foreach $count ( sort keys %data ){ # there's a better notation for this but $data{$count}->@ # never works for my foreachs ;-> foreach $type_hash ( @{ $data{$count} } ) { print "$count"; # just to make it easier to see, loop through the keys # for the type hash in your order. NB type_hash is # hash ref ($$type_hash) foreach $val ( (qw(type a_point z_point error) ) ) { print " --> $$type_hash{$val}"; } # foreach val print "\n"; } # foreach type_hash } # foreach count