... for (;;) { // --- add this printf("\n"); // the prompt fflush(stdout); // make sure output gets written // --- if (fi) { if (!fgets(slowo,32,fi)) break; ... #### ... sub read_sap_response { while (my $line = ) { last if $line =~ /^$/; # found "prompt" --> exit loop print $line; # show response } } my $pid = fork; if ($pid) { close PARENTR; close PARENTW; read_sap_response(); # this is needed, because we've patched the program to output # the blank line _before_ waiting for input (which was the # easiest option in this case...) while (1) { open FIFOR, "; close FIFOR; print SAPW $line; read_sap_response(); } } else { close SAPR; close SAPW; open STDIN , '<&PARENTR'; open STDOUT, '>&PARENTW'; exec "sap"; die $!; }