$SIG{ALRM} = \&timed_out; eval { alarm (10); $buf = <>; alarm(0); # Cancel the pending alarm if user responds. }; if ($@ =~ /GOT TIRED OF WAITING/) { print "Timed out. Proceeding with default\n"; .... } sub timed_out { die "GOT TIRED OF WAITING"; }