for (my $i=1; $i <= @rocks; $i++) { my $nextitem = $rocks[- $i]; # Take the ${i}th item from the end }