#!/usr/bin/perl use warnings; use strict; # may not work on windows use Term::ReadLine; my $t = new Term::ReadLine 'timeout test'; my $input; eval { local $SIG{ALRM} = sub { die ("timeout\n") }; alarm 10; $input = $t->readline("Enter something within 10 seconds: "); alarm 0; }; print( ( $@ =~ /timeout/ ) ? "\nYou loose!\n" : "You win: $input\n" );