considering 2 files has the same number of lines and fields
use strict;
use warnings;
use Data::Dumper;
#first data file
open my $fh1, '<', '1.txt' or die $!;
#seecond data file
open my $fh2, '<', '2.txt' or die $!;
#output file
open my $out, '>', 'out.txt' or die $!;
while (!eof($fh1) and !eof($fh2)) {
my $line1 = <$fh1>;
my $line2 = <$fh2>;
my @l1 = split /\s+/, $line1;
my @l2 = split /\s+/, $line2;
my @newvalues;
my $i = 0;
for (@l1){
push @newvalues, $_ + $l2[$i];
$i++;
}
print Dumper \@newvalues;
my $new = join ' ', @newvalues;
print $out $new."\n";
}
## EDIT ##
see @hwnd version below for a cleaner and more compact code on how to solve this problem