use threads; use threads::shared; $| ++; my $line = ""; share($line); sub read_stdin { while () { lock($line); $line = $_; print "child read in: $_\n"; } } threads->create(\&read_stdin); while (1) { if ($line ne "") { lock($line); print "parent process $line\n"; $line = ""; } else { print "do something else\n"; sleep(1);#this nothing but to slow down the prints } }