foreach my $index (reverse 0 .. $#links) { $response = $browser->get($links[$index]); splice(@links, $index, 1) unless $response->content_type eq 'text/html' || $response->content_type eq 'text/plain'; }