You can put multiple handles into an
IO::Select object, so you can include (for instance) STDIN along with your TCP sockets and get notified when there's either console input or TCP input ready to read. There are also modules like
Event and
POE that provide an event loop that can include IO, and may make it easier to write such a program.
There is a Net::Telnet module that can make your life easier if you're dealing with a remote host over Telnet.