#! perl -slw use strict; use threads; use threads::shared; use LWP::Simple; use HTML::TreeBuilder::XPath; sub locked(\$) :lvalue { lock ${$_[0]}; ${$_[0]} } our $T //= 3; my $stdoutSem :shared; my $running :shared = 0; while( my $url = <> ) { chomp $url; async { ++locked( $running ); if( my $content = get $url ) { my $tree = HTML::TreeBuilder::XPath->new(); $tree->parse( $content ); # do some processing here on the content if( my $title = $tree->findnodes( '/html/head/title' ) ) { chomp $title; lock $stdoutSem; print "$url : $title "; } # once done then delete the root node $tree->delete(); } --locked( $running ); }->detach; Win32::Sleep 500 while $running >= $T; } #### thisScript.pl urls.list > output.file