Insert this line and the solution will reveal before your weary eyes...
Hint: You need to escape $?.print "$command ; echo COMMAND_RET:$? | sed 's/^/COMMAND_OUT: /g'; ech +o -n END_; echo EXPECT\n";
Why not get rid of the sed-invocation?
Depending on the shells flavour of echo, you could also get rid of the second echo invocation.$exp->send("$command ; echo 'COMMAND_OUT: COMMAND_RET:'\$?; echo END_E +XPECT\n");
In Section
Seekers of Perl Wisdom