while ( my ($key,$value) = each %$h_ref1 ) { # Test key and value in %$h_ref2 # according to whatever criteria you need. }