#initialize array @array = (12,7,4); $i=0; foreach (@array) { #Throw in a hash to look up in a second $hash{$_} = $i; $i++; } #sort it, loop through, and look up from hash from above foreach (@num_sorted_array = sort { $a <=> $b } @array) { print "$_ came from \$array\[$hash{$_}\]\n"; }