%hash1 = qw( a b c d e f ); %hash2 = qw( a J e K y z ); @sharedKeys = grep defined( $hash2{ $_ } ), keys %hash1; @hash1{ @sharedKeys } = @hash2{ @sharedKeys };; print %hash1;; e K c d a J