my @result; $SIG{ALRM} = sub { die "timeout" }; eval { alarm(3); @result = `extApp $_`; #Not returning if extApp hangs alarm(0); }; if ($@) { if ($@ =~ /timeout/i) { push(@result, "App has hanged itself."); } else { alarm(0); # clear the still-pending alarm die; # propagate unexpected exception } }