#!/usr/bin/perl use strict; my $timeout = 5; while (1) { my $str = getstr($timeout); if ($str ne '') { print "Got it! $str"; } else { print "I got nothing.\n"; } } #----------------------------------------------------------- sub getstr { my ($timeout) = @_; my ($rin, $rout); vec($rin,fileno(STDIN),1) = 1; print "You have $timeout seconds to enter a string:\n"; my $input = select($rout=$rin, undef, undef, $timeout); if ($input) { return ; } else { return ''; } }