#!/usr/bin/perl use strict; use warnings; my %HASH; open(F1,"file1"); while () { chomp; my ($k,$v) = split /\s+/,$_,2; $HASH{$k} = $v; } close(F1); open(F2,"file2"); while () { chomp; my ($k,$v) = split /\s+/,$_,2; if (exists $HASH{$k} ) { $HASH{$k} *= $v; }else{ $HASH{$k} = $v; } } close(F2); # write output to file open(OUT,">newfile"); while (my ($k,$v) = each %HASH) { print OUT "$k $v\n"; } close(OUT);