perl -wMstrict -e "my %X = qw(a 1 b 2 c 3 z 9); my %Y = qw(d 4 e 5 f 6 z 8); my %X_not_in_Y = %X; my %Y_not_in_X = %Y; delete @X_not_in_Y{ keys %Y }; delete @Y_not_in_X{ keys %X }; print qq(X not in Y: @{[ keys %X_not_in_Y ]} \n); print qq(Y not in X: @{[ keys %Y_not_in_X ]})" X not in Y: c a b Y not in X: e d f