in reply to Checking if a non-blocking socket is active

You should be able to use select() or IO::Select with a zero timeout to poll for data socket activity (inclusing closure). Ideally you should use it with a timeout when you're waiting for socket input.