in reply to Reading and writing sockets
To determine if there is anything to read use select() (see IO::Select)