use strict; use warnings; use Data::Dumper; use List::Util qw(min max sum); my %hash; my @files = ('file1.txt','file2.txt'); for my $file (@files) { open(my $fh,"<",$file) or die "$file: $!"; while (my $line = <$fh>) { chomp $line; next unless $line; my @items = split(/\s+/,$line); my $key = shift @items; my $total = shift @items; $hash{$key}{'sum'} += $total; push(@{ $hash{$key}{'points'} }, @items ); } close($fh); } for my $key (keys %hash) { my $points = $hash{$key}{'points'}; $hash{$key}{'min'} = min(@$points); $hash{$key}{'max'} = max(@$points); $hash{$key}{'avg'} = $hash{$key}{'sum'} / @$points; # to print the points print join(' ',@$points) . "\n"; } print Dumper(\%hash);