in reply to Poll with socket handlers
See select or IO::Select, which can handle multiple sockets. And maybe you can show some self-contained simple code that demonstrates what you're doing and where you encounter problems?