in reply to Expect.pm dealing with STDOUT

I think you need to save the instance from the "new Expect" or do something like the following:
my $expect_instance = Expect->spawn( "telnet $router" ); my $cmd = 'terminal length 0'; print $expect_instance "$cmd\r"; my( $which, $why, $match, $before, $after ) = $expect_instance->expect +( $timeout, $prompt ); if( ! $which ) { die "Could not send $cmd to $router. Reason: $why"; }

You would want to check on $before, $after, and if you had multiple possible matches then $match. In the example above it is matching on $prompt, and thus $before is what came before the match and $after is what followed it. Note that these can be strings with new lines in them.

It has been a while since I used Expect.pm so I hope this helps.