#! perl -slw use strict; use threads qw[ async ]; use Net::Telnet; sub remoteCmd { my( $host, $user, $pass, @cmds ) = @_ my $t = new Net::Telnet( Timeout => 2810, Prompt => '/%/', Host => $host ); $t->login( $user, $pass ); $t->cmd( $_ ) for @cmds; $t->close; } my @hosts = ( [ qw[ 111.111.111.001 user pass ] ], [ qw[ 111.111.111.002 user pass ] ], [ qw[ 111.111.111.003 user pass ] ], [ qw[ 111.111.111.004 user pass ] ], [ qw[ 111.111.111.005 user pass ] ], [ qw[ 111.111.111.006 user pass ] ], [ qw[ 111.111.111.007 user pass ] ], ); my @cmds = ( 'cd ~', 'ls -l' ); ## These three lines do all the work. my $count : shared = @hosts; async{ remoteCMD( @$_, @cmds ); $count-- }->detach for @hosts; sleep 1 while $count--;