my @commands_run; foreach my $command1 (@commands) { chomp $command1; my $command_run = $ssh->exec($command1); print $command_run; push @commands_run, $command1; } print @commands_run;