# Instead of this: # $exp->send( "hostname\n" ); # $exp->expect( $timeout, $shell_prompt ); # # Try something like this $exp->send( "echo START_COMMAND; hostname; echo END_COMMAND" ); $exp->expect( $timout, [ qr/START_COMMAND\n(.*)END_COMMAND.*?$shell_prompt/, sub {}, # do whatever with the data... ], );