sub call_cmd{ my $host = shift; my $cmd = shift; my $command = $cmd; my $message; open( DIR, "$cmd|" ) || die "No cmd: $cmd $!"; while(){ $message.=$_; print "\n $host $message \n"; close DIR; } print "I'm here"; } #### foreach(@machines){ my $_ = threads->create(thread_creation,$_); $SIG{ALRM} = sub { $_->kill('ALRM') }; push(@threads,$_); } sub thread_creation(){ my $host = $_; eval{ $SIG{ALRM} = sub { die; }; alarm(5); ssh_con($host,"pblue"); alarm(0); } }