$exp->raw_pty(1); $exp->spawn(sprintf("%s %s -l %s %s", $cmd, $sshOpt, $userObj->user(), $remoteHost)); $exp->expect(10000, [ => sub { $_[0]->send(); } ]); ... $exp->expect(10000, [ => sub { $_[0]->send(); } ]);