my $infile = "/tmp/foo.in"; my $outfile = "/tmp/foo.out"; my $binary = "./output.pl"; system("mkfifo $infile"); system("$binary < $infile > $outfile &"); open(DATA_OUT, ">$infile"); open(DATA_IN, "<$outfile"); while($line = ) { chomp $line; print "Got $line\n"; if ($line =~ /\?/) { print DATA_OUT, "blah\n"; } } close(DATA_OUT); close(DATA_IN); system("rm $infile $outfile");