See this previous thread: Non-blocking Reads from Pipe Filehandle
In reply to Re^2: working with 2 inputs by salva in thread working with 2 inputs by sktron