$sort_line_contents->{element_one}->{element_two} #### $sort_line_contents->{1}->{2} = Item1; $sort_line_contents->{0}->{3} = Item2; $sort_line_contents->{1}->{4} = Item3; $sort_line_contents->{1}->{5} = Item4; $sort_line_contents->{2}->{6} = Item5; #### my @hash_keys2 = sort { %{$sort_line_contents}->{$b} <=> %{$sort_line_contents}->{$a} } keys %{$sort_line_contents}; #### foreach (reverse sort keys %{$sort_line_contents}) { push(@hash_keys2,$_);} #### foreach my $hk (@hash_keys2){ my @filli = sort { $sort_line_contents->{$hk}->{$a} <=> $sort_line_contents->{$hk}->{$b} } keys %{$sort_line_contents->{$hk}}; foreach (@filli){ #output to other part of program } }