use strict; use warnings; use threads; use Thread::Queue; $|++ ; # Create terminal watcher print "Create terminal watcher...\n"; my $Q_stdin = Thread::Queue->new; async { while (defined( $_ = )) { chomp ; print "\n+IN : '$_' " ; $Q_stdin->enqueue( $_ ) ; # print "|" ; sleep(2) ; ### Optional sleep() after input <<<< print "*" ; } ; }->detach; # close STDIN ; ### no longer our business <<<< my $Q_found = Thread::Queue->new; my $cmd; print "Awaiting commands...\n"; MAIN_LOOP: while (not defined $cmd or $cmd !~ /^q/i) { print "_" ; sleep(1); # Reduce load print "." ; # Process commands $cmd = $Q_stdin->dequeue_nb; if (defined $cmd) { print "\n-IN : '$cmd' " ; if ($cmd =~ /^q/i) { print "\nResolving open threads\n"; } else { async { print "\n+OUT: '$cmd' " ; $Q_found->enqueue( $cmd ) ; }->detach; } } # Print announcements while (defined(my $output = $Q_found->dequeue_nb)) { print "\n-OUT: '$output' "; } }