my %sorted = sort { $patients->{$a}{old_file} cmp $patients->{$b}{old_file} } (keys %{$patients}); my $patients = \%sorted; # or put { } around the sort expression to do it one line.