$Expect::Exp_Internal = 1; my $exp = Expect->new(); #$exp->log_stdout(1); $exp->spawn("scp test\.txt foo\@bar:/tmp/test\.txt ") or warn("Unable to spwan : $!"); $exp->expect(9, [ qr/Are you sure you want to continue connecting \(yes\/no\)\?/i, sub { my $self = shift; $self->send("yes\n"); exp_continue; }], [ qr/password:/i, sub { my $self = shift; $self->send("$passwd\n"); exp_continue; }]) or warn("error : " .$exp->exp_error()); #### Spawned 'scp test.txt foo@bar:/tmp/test.txt ' spawn id(6) Pid: 17288 Tty: /dev/pts/1 Expect::spawn('Expect=GLOB(0x87a04a8)','scp test.txt foo@bar:/tmp/test.txt co...') called at ... main::foo_project('ARRAY(0x8166e00)') called at ..... Starting EXPECT pattern matching... Expect::expect('Expect=GLOB(0x87a04a8)',9,'ARRAY(0x89e0d04)','ARRAY(0x89e8748)') called at ... main::foo_project_project('ARRAY(0x8166e00)') called at .... spawn id(6): list of patterns: #1: -re `(?i-xsm:Are you sure you want to continue connecting \(yes/no\)\?)' #2: -re `(?i-xsm:password:)' spawn id(6): Does `' match: pattern #1: -re `(?i-xsm:Are you sure you want to continue connecting \(yes/no\)\?)'? No. pattern #2: -re `(?i-xsm:password:)'? No. Waiting for new data (9 seconds)... TIMEOUT Returning from expect with TIMEOUT or EOF error : 1:TIMEOUT at .... foo@bar's password: