#!/usr/bin/perl -w $|++; use strict; my ($input, $failed); STARTIT: eval { local $SIG{ALRM} = sub { die "timed out\n" }; print 'You have 10 seconds. Type fast: '; alarm 10; chomp( $input = ); alarm 0; }; if ($@) { if ($@ eq "timed out\n") { if (++$failed == 3) { print "\nTimed out 3 times. You're toast!\n\n" and exit; } else { print "\nTimed out. Try again!\n\n"; } } else { die "Unhandled error: $@"; } } else { print "You said '$input'. 10 more seconds now!\n\n"; } goto STARTIT;