$exp->expect($timeout, [ qr'login: $', sub { $spawn_ok = 1; my $fh = shift; $fh->send("$sshUsername\n"); exp_continue; } ], [ 'password: $', sub { my $fh = shift; print $fh "$sshPWD\n"; exp_continue; } ], # I need your help here [ qr'/[root@]$/' => sub { my $fh = shift; print "regular exp matched \n"; $fh->send("cd /u0x/tmp\n"); exp_continue; } ] );