sort { $a->{NAME} cmp $b->{NAME} # compare name (will return 0 if they are the same), using alphabetic order (cmp) or $a->{AGE} <=> $b->{AGE} # compare age only if the names are equal, use numeric order (<=>) } @people;