sub process_text { my ($a_text) = @_; while (1) { my $key; my $wait_until = time + 3; while ( time < $wait_until ) { ReadMode 3; $key = ReadKey( -1 ); if ( defined $key ) { print "keystroke $key\t"; } ReadMode 0; } print_some_random_text($a_text); } } sub print_some_random_text { my ($a_text) = @_; # Replacing the next line with meaningful code is left as # an exercise for the OP. ## print "[Debug]\n"; }