$SIG{ALRM} = sub { die "timeout"; }; eval { alarm(60); # shouldn't take more than a minute # do something here alarm(0); # if the last op finished, cancel the alarm }; if ($@ =~ /timeout/) { # you know it didn't finish } else { # continue }