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); } }