until (eof FILE) { for my $count (3, 2) { my @set = map scalar , 1 .. $count; my ($time, @totals); for (@set) { chomp; my @f = split /\t/; $time ||= shift @f; # only want the FIRST time $totals[$_] += $f[$_] for 0 .. $#f; } print OUT join("\t", $time, map $_/$count, @totals), "\n"; } }