Try this:
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(switch say);
my %record;
while (<>) {
chomp;
my ($cell, $freq, $num) = split " ";
push @{$record{$cell}->{$freq}}, $num;
}
while (my ($cell, $freqs) = each %record) {
while (my ($freq, $nums) = each %$freqs) {
say "$cell $freq ", join(" ", @$nums);
}
}
Run it like this:
./t.pl input1.txt input2.txt