use Proc::Watchdog; my $w = Proc::Watchdog->new( { -path => '/tmp' } ); # stop process in 5 mins regardless of outcome $w->alarm(5); sub do_while { print "hi\n" while 1; } do_while(); $w->reset;