while () { my ($key, $x, $y) = split; my @from_cache = split ' ', $cache{$key}; $from_cache[0] += $x; $from_cache[1] += $y; $cache{$key} = join ' ', @from_cache; }