use strict; use warnings; use Net::SSH::Expect; use Data::Dumper; my $user = "user"; my $pwd = "password"; my $host = "host1"; my $local_port = 4100; my $remote_host = "host2"; my $remote_port = 22; my $raw_pty = 1; my $timeout = 3; my $rc = undef; my $ssh_option = "-L $local_port:$remote_host:$remote_port"; my $ssh1 = Net::SSH::Expect->new( host => $host, password => "$pwd", user => "$user", raw_pty => $raw_pty, timeout => $timeout, ssh_option => "$ssh_option" ); eval{ $rc = $ssh1->login(); }; die $@ unless defined $rc; print $rc;