use strict; use warnings; my @MasterMachineIndex = qw( # For example ... remote_host_1 remote_host_2 remote_host_3 ); foreach $Host (@MasterMachineIndex) { &ping; # my subroutine to ping system...works fine $Cmd = "rsh $Host uptime"; my $result = ""; eval { local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required alarm $timeout; $result = `$Cmd`; alarm 0; }; if ($@) { ($@ eq "alarm\n") or die "Unexpected error\n"; # Handle timeout here. } else { # Success here. } # ... }