use threads; use IO::Socket; open(IPS, "$ARGV[0]"); my @target = ; close(IPS); my $process_this_many = @target; my $max_threads = "20"; my $worker = 0; while ($worker <= $process_this_many) { for (my $x = 1; $x <= $max_threads && $worker <= $process_this_many; $x++) { $thr = threads->new(\&sub1, "$target[$x]"); #print "Start $x $worker\n"; $worker++; } # Loop through all the threads foreach $thr (threads->list) { # Don't join the main thread or ourselves if ($thr->tid && !threads::equal($thr, threads->self)) { $data = $thr->detach; #print "$data\n"; } } } sub sub1 { my $t = shift; $con = IO::Socket::INET->new(Proto => "tcp", PeerAddr => "$t", PeerPort => "3306" , Timeout => 5) || die "\n+ Connection failed...\n"; while($ams = <$con>) { print $_ } shutdown($con,2); }