my %from_to_bytes; my %col_headings; while () { ( $from, $to, $hh, $mm, $bytes ) = /^(\S+) (\S+) (\d+):(\d+) (\d+)$/ or ( warn "bad format on line $.: $_" ), next; $from_to_bytes{$from}{$to} += $bytes; $from_to_bytes{$from}{"~~TOTAL"} += $bytes; $from_to_bytes{"~~TOTAL"}{$to} += $bytes; $col_headings{$to} = undef; }