This looks like a bug on Net::SSH::Perl.
I can reproduce the problem myself. In my environment, Net::SSH::Perl hangs at some point between 8000 and 10000 characters.
Net::OpenSSH can handle the same commands without any issue (that's why I think the problem lies on Net::SSH::Perl):
#!/usr/bin/perl
use strict;
use Net::OpenSSH;
use Net::SSH::Perl;
my $host = $ARGV[0] // "localhost";
for my $len (10, 100, 1000, 2000, 4000, 6000, 8000, 10000, 20000, 5000
+0) {
my $cmd = "echo ";
$cmd .= "." x $len;
warn "trying with Net::OpenSSH, len=$len...\n";
my $ssh1 = Net::OpenSSH->new($host);
my ($stdout1, $stderr1) = $ssh1->capture($cmd) or die "Failed!\n";
warn "Failed $?!\n" if $?;
warn "trying with Net::SSH::Perl, len=$len...\n";
my $ssh2 = Net::SSH::Perl->new( $host,
# debug => 1,
options => [ "BatchMode yes",
"PasswordAuthenticati
+on no",
"ConnectTimeout 15" ]
+ );
$ssh2->login("root") or die "Failed to login: $!\n";
warn "logged\n";
my ($stdout2, $stderr2, $exit) = $ssh2->cmd($cmd);
warn "Failed $exit!\n" if $exit;
}