use strict; use warnings; # Open your $rh and authenticate here # ... open(my $fh, "+>>default_ve.txt") || die "Couldn't open file: $!"; my @lines = $rh->cmd(String => 'show version | no-more', Prompt => '/\n\S+\>/'); foreach my $line (@lines) { print $fh $line; } close $fh; # Close $rh or do more stuff here # ...