for my $key (keys %hash) { if (exists $hash{$key}{FILE1}) { if (exists $hash{$key}{FILE2}) { # Key exists in both files } else { # Key exists only in file 1 } } else { # Key exists only in file 2 } }