use strict; use threads; 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'); 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 }