#!/usr/bin/perl -w $| = 1; use strict; my $answer = 'n'; eval { local $SIG{ALRM} = sub { die("timed out\n"); }; print "Invoke script? (y/n) "; alarm(10); chomp( $answer = ); alarm(0); # reset the alarm so it won't go off later }; # user entered text other than 'y' or else the 10s is up if ($@ eq "timed out\n" or lc($answer) ne 'y') { die("No positive answer. Aborting execution.\n"); } # some other error blew within the eval - best to die() elsif ($@) { die($@); } # we got the 'y' answer, so now we continue: print "Executing remainder of script.\n";