my @names_marks = ("cliff 76", "john 52", "keith 90", "rob 52"); my (%hash, @names, @marks); foreach (@names_marks) { my ($name, $mark) = split / /, $_; $hash{$_} = [ucfirst($name), $mark]; } ## then sort by the $mark foreach my $key (sort {$b->[1] <=> $a->[1]} keys %hash) { print "\$key: $key \$value: $hash{$key}->[0] $hash{$key}->[1]\n"; }