my $pre_pass_prompt = q{Do \s you \s want \s to \s send \s anyway}; # save the current prompt my $current_prompt = $obj->prompt; # wait for the prompt $obj->waitfor(Match => m{$current_prompt}smx, Match => $pre_pass_prompt); # # check if the last prompt matched it's the $pre_pass_prompt if ($obj->last_prompt() =~ m{$pre_pass_prompt}smx) { # send the reply $obj->cmd(q{y}); }