On a UNIX-type system, I would use a signal handler to catch ALRM events, and then use the alarm function to start a timer before starting an action, which, as I expected, could be a timeout. If the action is completed, I would use the alarm (0) to turn off the alarm and exit normally, otherwise the signal handler must raise it to gracefully close everything.
I did not work with perl on Windows at the time, and although Windows is somewhat POSIXy, I cannot guarantee that this will work; you will need to check perl documentation to see if signals are supported on your platform or to what extent.
alarm() Perl Cookbook. , :
eval {
local $SIG{ALRM} = sub {
print "Print this if we time out, then die.\n";
die "alarm\n";
};
alarm(90);
routine_that_might_take_a_while();
alarm(0);
};