sub sortHash { my $hash = shift; my @keys = sort { @a = split(/[,-]/, $hash->{$a}); @b = split(/[,-]/, $hash->{$b}); $a[0] cmp $b[0] || $a[1] <=> $b[1] } keys(%{$hash}); return \@keys; } #### my %hash = ( '2.2.2.2' => 'nfs,1', '6.6.6.6' => 'afp-0', '3.3.3.3' => 'nfs-0', '4.4.4.4' => 'cifs,1', '1.1.1.1' => 'cifs,0', ); #### my $array = &sortHash(\%hash); print Dumper($array); # will print $VAR = [ '6.6.6.6', '1.1.1.1', '4.4.4.4', '3.3.3.3', '2.2.2.2', ];