sub foo { return $self->{'atoms'}{$a}->atomName cmp $self->{'atoms'}{$b}->atomName; } my @sorted = sort foo @unsorted;