http://www.perlmonks.org?node_id=1106037


in reply to Re^4: use sysread to read non-blocking filehandle
in thread use sysread to read non-blocking filehandle

You could check whether you closed your session and don't expect any more data. Maybe eof could help there too.

Using these two criteria, you should be able to determine whether there was just not anything read, or whether the other end has closed the connection.