#!/usr/local/bin/perl use warnings; use strict; my ($key, $first, $second) = split ' ', <>; while (<>) { my @line = split; if ($key eq $line[0]) { $first += $line[1]; $second += $line[2]; } else { print "$key $first $second\n"; ($key, $first, $second) = @line; } } print "$key $first $second\n";