#! perl -slw use strict; use Term::ReadKey; $| = 1; sub ReadLine { my $timeout = shift; my $start = time; ReadMode 1; my $buf; while( time < $start + $timeout ) { if( my $c = ReadKey 0.5 ) { printf $c; $buf .= $c; ReadMode( 0 ), return $buf if ord( $c ) == 13; } } ReadMode 0; return undef; } for my $n ( 1 .. 10 ) { if( my $buf = ReadLine( 10 ) ) { print "$n Got $buf"; } else { print "$n timed out"; } } __END__ [16:35:02.57] P:\test>alarmed.pl Subroutine ReadLine redefined at P:\test\alarmed.pl line 7. 1 Got fred 2 Got bill 3 Got John 4 timed out 5 timed out 6 timed out 7 Got blech 8 Got one 9 Got two three 10 Got four