for my $student (sort {$students{$a}{id} <=> $students{$b}{id}} keys %students) { print "$student => $students{$student}{id}\n"; }