my %result; my %hash = ( '2.1','AB', '2.2','AB-1', '4.1','AB-4', '4.2','AB-6', '21.01','AB', '22.12','AB-1', '41.44','AB-4', '42.46','AB-6', '42.46','AB-6', '01.10','AB', '20.02','AB-1', '40.04','AB-4', '02.26','AB-6', '56.01','AB', '56.12','AB-1', '65.44','AB-4', '65.46','AB-6'); 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 = "$fields[0].$fields[1]"; if (exists $hash{$key}) { $key = $hash{$key}; if (exists($result{$key})) { $result{$key} += $fields[03]; } else { $result{$key} += $fields[03]; } } } } close FILE;