my @links = (... initial set ...); while (@links) { my $one = shift @links; ... process $one ... push @links, (... more to do... ); }