my $nextitem; while ($nextitem = pop @rocks) { # Use $nextitem }