my (%r1,%r2,%r3,%r4); my $Total; foreach my $file (@files) { open FILE, "<$dir/$file" or warn "Couldn't open file ($!) or file ($!) not found\n"; while (chomp ( my @fields = split /\t/, ) ) { my $key = "$f[0].$f[1]"; if ($c{$key}) { $key = $c{$key}; if (exists($r1{$key})){ $r1{$key} += $f[02]; } else { $r1{$key} += $f[02]; } $Total +=$r1{$key}; } } $r1{'Total'} = $Total; } close FILE; #### A B 12.00 C D 13.00 E F 11.00 G H 22.00 #### foreach my $file (@files) { open FILE, "<$dir/$file" or warn "Couldn't open file ($!) or file ($!) not found\n"; while (chomp ( my @fields = split /\t/, ) ) { my $key = "$f[1].$f[2]"; $key{'Output - Final'}=1; if ($c{$key}) { $key = $c{$key}; if (exists($r1{$key})){ $r1{$key} += $f[03]; } else { $r1{$key} += $f[03]; } $Total +=$r1{$key}; } } $r1{'Total'} = $Total; } close FILE; #### 1 A B 12.00 2 C D 13.00 3 E F 11.00 4 G H 22.00 #### r1 --> hash contains data as ... Key Value Name F1.A AB 12.00 CD 13.00 EF 11.00 GH 22.00 r2 --> hash contains data as ... Key Value Name F2.B AB 01.00 CD 04.00 EF 42.00 GH 34.00 r3 --> hash contains data as ... Key Value Name F3.C AB 02.00 CD 03.00 EF 15.00 GH 20.00 r4 --> hash contains data as ... Key Value Name F4.D AB 62.00 CD 43.00 EF 24.00 GH 26.00 #### Output - Final Name F1.A F2.B F3.C F4.D AB 12.00 01.00 02.00 62.00 CD 13.00 04.00 03.00 43.00 EF 11.00 42.00 15.00 24.00 GH 22.00 34.00 20.00 26.00 Total 58.00 81.00 40.00 155.00