sub server_sort { # bi-valued key = 0 if {tag} is not 53 and 1 if {tag} is 53 (($my_server_hash{$a}{tag} == 53) <=> ($my_server_hash{$b}{tag} == 53)) || $a cmp $b || $my_server_hash{$a}{tag} <=> $my_server_hash{$b}{tag} } my @server_names = sort &server_sort keys %my_server_hash; # now the server names are sorted with the 53 tags grouped # separately from the rest.