my $new_key = 'NEW'; my $new_value = 'Value'; if (exists $file_hash{$new_key} && $file_hash{$new_key} eq $new_value) { # add to another hash, per the comment in your post } else { $file_hash{$new_key} = $new_value; }