Yes, it is quite possible.
The obvious approach would be to have Alice and Bob perform a Balanced Password Authenticated Key Exchange (PAKE) protocol, with $A$ and $B$ being their 'passwords'. If they come up with the same shared secret, $A=B$, and if they come up with $A \ne B$ and they don't learn anything else about $A$ and $B$
There are a number of PAKE protocols out there; see the wikipedia article for some of the more common ones.
One such way (which is simplified CPACE) to compare the values $a$ known to Alice and $b$ known to Bob would be to select unrelated values $G$ and $N$ (I wrote this assuming elliptic curves; it can be directly translated to a modp group, except that the subtraction becomes a moduluar inversion) and:
Alice selects a random value $r$ and computes $C = r G + a N$; she sends $C$
Bob selects a random value $s$ and computes $D = s G + b N$; he sends $D$
Alice computes $S = r (D - a N)$; Bob computes $T = s (C - b N)$; if $a=b$, then $S=T$; otherwise they're unrelated.
Alice and Bob can either send $S$ and $T$ to each other (if they trust the other side to be honest), or alternatively use those to generate encryption keys and do a simple verification protocol.