in reply to Problem handling 2 simultaneous socket streams

I started writing a mini-tutorial explaining why readline (aka <$fh>) interacts badly with select.

On that same line, your use of can_write is broken. 1) It can also block. 2) It might not return all sockets, in which case you'll suffer data loss. I can't go into details right now, so I'll push you in the right direction: You need to use an output buffer for each writer socket and use IO::Select::select($readers, $writers, undef) where you currently use can_read.

It's much easier to do using threads.