## your code is effectively this: my %hash_list = ( " Bill 34", " Jane 28", " John 20", " Tom 19", " Wall 18" ); ## which means... my %hash_list = ( # key # value " Bill 34" => " Jane 28", " John 20" => " Tom 19", " Wall 18 => undef ); #### print sort ( split( /,/, $names ) ); #### my $names = "John 20, Bill 34... etc"; my @elems = split( /\s*,\s*/, $names ); my %num2name = map{ reverse split( /\s/, $_ ) } @elems; my @sorted = map{ $num2name{$_} } sort { $a <=> $b } keys %num2name; print "@sorted\n";