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; }