my @q; while (@q) { my $item = shift(@q); # Insertion ... push @q, ...; # Removal ... }