#Suppose you got a new XML key and value read from the file in $key and $value if (not exists $hash{$key}) { $hash{$key}= $value; } else { #drop key }