in reply to Running Perl in an Expect loop
See also IPC::PerlSSH, another framework that allows you to run Perl code on a remote connection.