use strict; use warnings; use Text::Table; my %totals; while () { my ($id, $date, $value) = split ' '; $totals{$date}{sum} += $value; ++$totals{$date}{count}; } my $tbl = Text::Table->new('Date', \' | ', 'Average'); for my $date (sort keys %totals) { $tbl->add($date, $totals{$date}{sum} / $totals{$date}{count}); } print $tbl; __END__ 1 0109 4 1 0209 5 1 0309 8 2 0109 6 2 0209 6 #### Date | Average 0109 | 5 0209 | 5.5 0309 | 8