foreach my $id ( map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ (split( "\t", $students{$_} ))[1], $_ ] } keys %students ) { printf "$id\t$students{$id}\n"; }