use strict; use Carp; use warnings; use autodie; use feature qw/say/; use Net::SSH::Expect; print "\n[INFO] script Execution Started\n"; #-- ssh into a router my $ssh = Net::SSH::Expect->new( host => "ip addr", password => 'password', user => 'user name', raw_pty => 1, ); my $login_output = $ssh->login(); #--Function to read config file and execute the commands on the router accordingly. sub mysub { my ($ssh,$filename) = @_; $ssh->exec("cmd 1"); $ssh->exec("cmd 2"); open my $p, '<', $filename; while (my $config = <$p>) { chomp $config; my $conf = $ssh->exec("$config"); print("$conf"); } } #--> Function call. mysub($ssh,"file name.txt");