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"; }