use strict; use warnings; open(my $file2, '<', "data1.txt") or die "failed to open 'output_1.txt $!"; open(my $file3, '>>', "combined.txt") or die "failed to open 'combined.txt $!"; while (<$file2>) { chomp; # delete new line character my @combined_data = $file3; my @list_file = split; print "$combined_data[1]" "$list_file[1]\n"; } close $file2; close $file3;