use strict; use warnings; use Data::Dumper; my %values; for my $line (@lines) { chomp $line; my ($epoch, $d, $m, $y, $value1, ...) = split ' ', $line; $values{$epoch}->{count}++; $values{$epoch}->{value1_sum} += $value1; ... } for my $epoch (keys %values) { my $value1_sum = delete $values{$epoch}->{value1_sum}; $values{$epoch}->{value1} = $value1_sum / $values{$epoch}->{count}; ... } print Dumper \%values;