$hash{g1} = Set::Scalar->new(qw(ATG1 ATG2 ATG4 ATRG7)); $hash{g2} = Set::Scalar->new(qw(ATG1 x y z)); if( $hash{g1}->intersection($hash{g2}) ) { print "merging g1 and g2\n"; $hash{g1}->insert(delete $hash{g2}) }