##
my @sorted = sort { $b cmp $a } @unsorted;
####
my $nextitem;
while ($nextitem = pop @rocks) {
# Use $nextitem
}
####
for (my $i=1; $i <= @rocks; $i++) {
my $nextitem = $rocks[- $i]; # Take the ${i}th item from the end
}