while (@work) { my $item = shift/pop @work; # Possibly push/unshift items onto @work }