$timeout = 5; $scp_command = "$SCP -v -r remoteuser@remote_host:/tmp/test /tmp/"; $Scp = Expect->spawn($scp_command); $Scp->log_stdout(0); $Scp->exp_internal(1); while ( $Scp->expect(2,"Are you sure you want to continue connecting (yes/no)?") ) { print $Scp "yes\n"; } sleep(60); $Scp->expect(1,"password:"); print $Scp "$password\n"; $Scp->soft_close(); $Scp->hard_close();