in reply to Sorting a multidimensional hash by column

KEY2 is a single key with a single value, so you can't sort that. Maybe you mean "by the second key"? But you don't say if you want to sort the keys or the values. OK, since you said KEY2 then I'll guess you want to sort the keys.

I added some data items to your hash, I don't know your data format, but I hope you get the idea. You might try this:
use strict; use warnings; my $hash; $hash->{"AAA"}->{"KEY1"} = "VALUE1"; $hash->{"AAA"}->{"KEY2"} = "VALUE2"; $hash->{"AAA"}->{"KEY3"} = "VALUE3"; $hash->{"AAA"}->{"KEY9"} = "VALUE3"; $hash->{"AAA"}->{"KEY10"} = "VALUE3"; $hash->{"AAA"}->{"KEY123"} = "VALUE3"; $hash->{"AAA"}->{"KAY1"} = "VALUE1"; $hash->{"AAA"}->{"KAY2"} = "VALUE2"; $hash->{"AAA"}->{"KAY3"} = "VALUE3"; my @result = sort keys %{$hash->{"AAA"}}; print "@result\n";
But that just gives:
KAY1 KAY2 KAY3 KEY1 KEY10 KEY123 KEY2 KEY3 KEY9
because the default sort is textual. We want a numeric sort on the second part of the key (I'm guessing here on your data format) so we need a bit more work:
sub keycmp { $a =~ /^(\D*)(\d*)$/; my $a_txt = $1; my $a_num = $2; $b =~ /^(\D*)(\d*)$/; my $b_txt = $1; my $b_num = $2; if ($a_txt eq $b_txt) { return $a_num <=> $b_num } else { return $a_txt cmp $b_txt } } @result = sort keycmp keys %{$hash->{"AAA"}}; print "@result\n";
Gives:
KAY1 KAY2 KAY3 KEY1 KEY2 KEY3 KEY9 KEY10 KEY123