in reply to what is EOF and how can I send it?

This is what Expect is for. The Expect module handles the pseudo-tty details, so you don't have to!

This program is called 'consumer.pl'. I added a clue for Expect to use to find the end of the output. You can do without the ending markers, you just have to be a little more clever with Expect. This sample program is similar to yours, in that it uses multiple input streams. It writes a file for each stream.

use File::Slurp; my $out=''; while(<>) { $out .= "1:$_"; } $out .= "end1\n"; write_file("out1.txt", $out); $out=''; while(<>) { $out .= "2:$_"; } $out .= "end2\n"; write_file("out2.txt", $out);
Here is a program to communicate with it, and send it two streams of data. The Expect module sends control-D with the string "\cD".
use Expect; my $proc= new Expect(); $proc->spawn("./consumer.pl"); $proc->send("hello there\n"); $proc->send("\cD"); $proc->send("this is\n"); $proc->send("\cD"); $proc->expect(1, [ /end1/ => sub { exp_continue; } ], [ /end2/ => sub { exp_continue; } ] );
I'm sure that this code could be better, it is intended as proof of concept. I have only used Expect a few times. I find it difficult but worthwhile.

minor update: pushed the code around a bit

It should work perfectly the first time! - toma