use strict; use warnings; use LWP::Simple; # Pre-load essential modules for extra stability. if ( $INC{'LWP/UserAgent.pm'} && !$INC{'Net/HTTP.pm'} ) { require IO::Handle; require Net::HTTP; require Net::HTTPS; } my @urls = ( 'http://hooboy.no-such-host.int/', 'http://us.a1.yimg.com/us.yimg.com/i/ww/m5v9.gif', 'http://www.guardian.co.uk/', 'http://www.ora.com/ask_tim/graphics/asktim_header_main.gif', 'http://www.pixunlimited.co.uk/siteheaders/Guardian.gif', 'http://www.yahoo.com', ) x 4; use Parallel::ForkManager; my $pm = new Parallel::ForkManager(8); if ( $^O ne 'MSWin32' ) { $pm->set_waitpid_blocking_sleep(0); } foreach my $url ( @urls ) { $pm->start and next; my ($type, $length, $mod) = head($url); # if (!defined $type) { # ... # } # elsif ($mod) { # ... # } # else { # ... # } print "$url is done\n"; $pm->finish; } $pm->wait_all_children;