#!/usr/bin/perl use strict; use warnings; my %set; my $set_cnt = 1; my $line_cnt = 0; while () { chomp; ++$line_cnt and next if /^\s*$/; if ($line_cnt == 2) { $line_cnt = 0; $set_cnt++ } my ($n, @m) = split /\s+/; $set{$n}->[$_] += $m[$_] for 0 .. $#m; } foreach my $k (sort { $a <=> $b } keys %set) { print $k, "\t"; print $_/$set_cnt, "\t" for @{$set{$k}}; print "\n"; } __DATA__ 90 0.0247481564832794 0.672855350654247 91 0.0179393727770228 0.681444966159488 92 0.0304371590737797 0.691292629756847 93 0.0262014613090327 0.707479206603499 94 0.0305333702130782 0.724031300019831 95 0.0525632991251114 0.753174235934156 90 0.0230764579156433 0.676198398681967 91 0.0282334103527949 0.684963109911959 92 0.0275317795328473 0.694989480270408 93 0.0301524562700934 0.70796497660355 94 0.037567005927381 0.729267549176281 95 0.0572362219534508 0.763883493442457