use strict; use warnings; my %data=(); for my $file (qw /file_1.txt file_2.txt, file_3.txt ... file_n.txt/) { open my $FH, "<", $file or die "could not open $file $!"; while (<$FH>) { chomp; my ($sz,$sum,@f) = split /\s+/; push @{$data{$sz}},$_ for @f; } close $FH; } # ...