Read
Bidirectional Communication with Another Process carefully (don't get in the situation when both programs wait for input from the other side), then proceed with examples from CPAN module
IPC::Run which provides a comfortable interface to bidirectional interaction with programs.