use IO::Handle; # do stuff my $input_thread = threads->new( \&getInput ); # start the thread, wait for input # do stuff if you feel like it my $input = $input_thread->join || 'default input'; # wait for thread to return sub getInput { my $h = IO::Handle->new_from_fd( *STDIN, r ); $h->blocking( 0 ); # don't wait for input to return from read()s my $time = time(); my $input = ''; while( 1 ){ $h->read( $input, 20, 0 ); # read 20 chars of info if it's available chomp $input; last if $input; # return if we got input last if time() - $time > 5; # return if 5 seconds have passed } }