# define signal handler to catch contol-c $SIG{'INT'} = 'catch_int'; sub catch_int { my $ans; system("clear"); while ($ans !~ /[Nn]/) { print "Do you want to exit [y or n]? "; chomp($ans=); if ($ans =~ /[Yy]/) { exit(0); } } }