use IPC::Open2; for my $id (@ids) { $wgets++; push @pids, open2(undef, undef, 'wget', $url.$id, '-q', '-O', $dir.$id); while ( @pids >= 10 ) { waitpid( shift @pids, 0 ); } } while ( @pids ) { waitpid( shift @pids, 0 ); } #### sub fetch_xml_data { my ($ids) = @_; my $dir = 'quicklook/'; my $url = 'http://api.eve-central.com/api/quicklook?typeid='; my $thread_count = 20; my $Q = new Thread::Queue; my @threads; for my $id (@{ $ids }) { $Q->enqueue( $id ); } for ( 1 .. $thread_count ) { push @threads, threads->create( sub { require LWP::Simple; while( my $id = $Q->dequeue ) { say "Downloading XML file for id $id.
"; LWP::Simple::getstore( $url.$id, $dir.$id ); } } ); $Q->enqueue( undef ); } $_->join for @threads; }