use strict; #use warnings; # I'm trying to simulate input from a textfile containing # lines of NameSpaceMarks my @names_marks = ("cliff 76", "john 52", "keith 90", "rob 52"); my (%hash, @names, @marks); foreach (@names_marks) { ($names[$_], $marks[$_]) = split / /, $_; $hash{"$marks[$_]".$names[$_]} = ucfirst($names[$_]). " " . $marks[$_]; } foreach my $key (sort {$b <=> $a} keys %hash) { # Prints each value print "\$key: $key \$value: $hash{$key}\n"; } #Output of print $key: 90keith $value: Keith 90 $key: 76cliff $value: Cliff 76 $key: 52rob $value: Rob 52 $key: 52john $value: John 52