#!/usr/bin/perl use strict; #no warnings; open (IN, "<", $ARGV[0]) || die "$!"; my %hash; while (){ chomp; my @array =split(',',$_); my $id = substr $array[1], 1,3; (defined $hash{$array[0]}{$id}) ? ($hash{$array[0]}{$id} += $array[2]) : ($hash{$array[0]}{$id} = $array[2]) ; } close IN; foreach my $prim (keys %hash){ foreach my $sec (keys %{$hash{$prim}}){ print "$prim, $sec, $hash{$prim}{$sec}\n"; } }