in reply to killing command if it takes too much time

Killing ssh client processes on timeouts is usually not a great idea as it will often leave orphan processes running on the remote host.

Anyway, maybe, that will do what you want...

use Net::OpenSSH '0.51_01'; my $ssh = Net::OpenSSH->new($ipaddress, user => 'pason', passwd => 'perlassasin27' +, timeout => $timeout, kill_ssh_on_timeout => 1); my @lines = $ssh->capture({stderr_to_stdout => 1}, scp => 'root@comp2:/tmp/10mbfile', '/tmp'); if (my $error = $ssh->error) { print $logfh, "scp command failed: $error\n"; }