while(@array1) { ONE: while(@array1) { my $item = shift @array1; # Do various things with $item, some of which will _possibly_ # push @array1, ... # and/or # push @array2, ... } TWO: while(@array2) { my $item = shift @array2; # Do various things with $item, some of which will _possibly_ # push @array2, ... # and/or # push @array1, ... } }