use strict; use warnings; # Place to accumulate the values my %sum; my $EquipName = "Switch"; my $slot = "1"; my $port = "FF"; while (my $INPUT_LINE = ) { chomp $INPUT_LINE; my $KEY = $EquipName . "." . $slot . "." . $port; # Fetch out the values for the current line my ($PvcCount, $LCir, $RCir) = split /\s+/, $INPUT_LINE; # Add the values to the accumulators $sum{PvcCount}{$KEY} += $PvcCount; $sum{LCir}{$KEY} += $LCir; $sum{RCir}{$KEY} += $RCir; # Print the current values print "Line $.: (PvcCount, LCir, RCir) " . "CUR:($PvcCount, $LCir, $RCir) " . "TTL:($sum{PvcCount}{$KEY}, $sum{LCir}{$KEY}, $sum{RCir}{$KEY})\n"; } __DATA__ 1 2 3 2 4 9 3 8 27 4 16 81