in reply to How do I record in what order a sort was preformed

You could perhaps use a second dimension to keep track where the element came from...
@array = (3,2,1); $array[4] = 0; my $i = 0; foreach ( sort { $a->[1] cmp $b->[1] } # or better <=> for numbers ins +tead of cmp map { [$i++, $_ ] } @array ){ my $number = $_->[1]; my $originalIndex = $_->[0]; # do something with $number and $originalIndex... } # foreach

Best regards,
perl -e "print a|r,p|d=>b|p=>chr 3**2 .7=>t and t"