I assume that you are using the Expect.pm module described here . As indicated there:
If the call in the context of the expect () array returns ($ matched_pattern_position, $ error, $ Successfully_matching_string, $ before_match and $ after_match).
Thus, you probably want to call it in the context of the array, so that you can get an error, both when re-expressing and when transferring unsuccessfully.
my ($matched_pattern_position, $error, $successfully_matching_string, $before_match, $after_match) = $exp->expect(30 , -re,".*bash-.*" => sub{$exp->send("$outfile2 >$outfile \r")} ); $exp->expect(60 ,-re,".*bash-.*" => sub{$exp->send("$shayam > $Ram \r")} ) if !defined $error;
source share