|Come for the quick hacks, stay for the epiphanies.
Any chance you can simply increase the timeout at the Cisco device end or as part of your telnet connection? Many years ago I used Net::Telnet to visit a series of Cisco routers. I found Net::Telnet to be very capable and configurable. Plus, once connected to the Cisco router I could issue local commands to configure my session. I don't recall all the Cisco syntax but maybe there is some at the Cisco device end to keep your connection alive or a setting in Net::Telnet (or Net::Telnet::Cisco which I've not yet used). Just some ideas...