I believe you could use DBD::AnyData.
Or, here's something based on bart's solution in the mentioned thread:
use strict;
use warnings;
my %data;
{
open(my $fh_in, '<', 'file1.txt')
or die("Can't open first input file: $!\n");
<$fh_in>; # Skip header.
while (<$fh_in>) {
chomp;
my ($upc, @fields) = split /,/;
push(@{$data{$key}}, @fields);
}
}
{
open(my $fh_in, '<', 'file2.txt')
or die("Can't open second input file: $!\n");
<$fh_in>; # Skip header.
while (<$fh_in>) {
chomp;
my @fields = split /,/;
my $upc = pop(@fields);
push(@{$data{$key}}, @fields);
}
}
{
open(my $fh_out, '>', 'file3.txt')
or die("Can't open output file: $!\n");
foreach (sort keys %data) {
print $fh_out (join(',', @$_), "\n");
}
}