@ranks[@sorted_positions] = (0 .. $#sorted_positions); #### @ranks[1, 3, 5, 7, 9] = (0, 1, 2, 3, 4); #### #!/usr/bin/env perl -l use strict; use warnings; my @ranks = qw{a b c d e f g h i j}; my @sorted_positions = (1, 3, 5, 7, 9); print "@ranks"; @ranks[@sorted_positions] = (0 .. $#sorted_positions); print "@ranks"; #### a b c d e f g h i j a 0 c 1 e 2 g 3 i 4