#!/usr/bin/perl use strict; use warnings; use threads; use Thread::Queue; # Create terminal watcher print "Create terminal watcher...\n"; my $Q_stdin = Thread::Queue->new; async { $Q_stdin->enqueue( $_ ) while defined( $_ = ); }->detach; my $Q_found = Thread::Queue->new; my $cmd; print "Awaiting commands...\n"; MAIN_LOOP: while (not defined $cmd or $cmd !~ /^q/i) { sleep(1); # Reduce load # Process commands $cmd = $Q_stdin->dequeue_nb; if (defined $cmd) { chomp $cmd; if ($cmd =~ /^q/i) { print "Resolving open threads\n"; } else { async { $Q_found->enqueue( $cmd ) ; }->detach; #$Q_found->enqueue( $cmd ) ; # using this in place of async works } } # Print announcements while (defined(my $output = $Q_found->dequeue_nb)) { print ">$output\n"; } } __END__ c:\test>junk9 Create terminal watcher... Awaiting commands... fred bill john >fred mary >bill quit >john Resolving open threads >mary