use strict; use threads; use threads::shared; ### I omitted this from my example above initially. use Thread::Queue; use ClarRPC; my $queue = new Thread::Queue; rpc('10.15.51.208', '1300', 'ping -n 50 10.15.51.208'); rpc('10.15.51.208', '1301', 'ping -n 10 10.15.51.208'); rpc('10.15.51.208', '1302', 'ping -n 50 10.15.51.208'); for( 1 .. 3 ) { ## Must iterate once for each thread started ### while (my $ref = $queue->dequeue) { my ($port, @results) = @$ref; print "$port : @results\n"; } } sub rpc { my ($ip, $port, $command) = @_; async{ my $connection = ClarRPC->connect($ip, $port); my @resp :shared = $connection->rpc( 'ClarRPCService::system_call', $command ); $connection->disconnect(); unshift(@resp, $port); $queue->enqueue(\@resp, undef); }->detach }