while (@array) { my $elem = pop @array; # or shift, to take from the front end # Do stuff with $elem here. }