my @a; for (my $i=0;$i<10;$i++) { my $filenum_str = sprintf "%03d", $i; my $filename = "/var/tmp/${filenum_str}"; my %b; create_hash_for_filename($filename,\%b); push @a, {%b}; } for my $key (keys %{$a[0]}) { for my $j (1..$#a) { if (exists $a[$j]{$key}) { #adding column 1 and 2 in 1st hash if found in other hashes and deleting from them $a[0]{$key}[0] +=$a[$j]{$key}[0]; $a[0]{$key}[1] +=$a[$j]{$key}[1]; # delete 1st and 2 nd column from other hashes delete $a[$j]{$key}; } } } print "now printing merged firat hash: for my $key (keys %{$a[0]}) { print "$key : $a[0]{$key}[0]: $a[0]{$key}[0] \n"; } sub create_hash_for_filename { my ($file , $hash) = @_; open (FILE, "< $file") or do { return(1,"$file couldnt be opened"); }; while() { my @match = split (' ', $_); $hash->{$match[0]} = [$match[1], $match[2]]; } close(FILE); }