#!/usr/bin/perl -w $SIG{ALRM} = sub { command() }; command(); if ($@) { if ($@ =~ /timeout/) { command(); } else { alarm(0); # clear the still-pending alarm die; # propagate unexpected exception } } sub command { my $date = `date`; chomp($date); alarm(5); print "\n"; print "prompt $date > "; <>; alarm(0); }