in reply to IPC:Open2 question
Consider using the Expect module to do this. It eliminates the problems you are experiencing right now, and allows you to handle many cases that your code is not.