foreach (keys %enthalpy_hash) { if (exists $hash{$_}) { push @common, "$_ = ", $enthalpy_hash{$_} * $hash{$_}, "\n"; push @total, $enthalpy_hash{$_} * $hash{$_}, "\n"; } # etc }