I think this might be a good job for paste.
plot "<paste A B" u 1:($2-$4) w points #whatever line style you want...
#xA #yA-yB
For the file where xA != xB, I'm a little unclear whether you want to plot only the set of points with are common to both (the intersection of the two sets) or whether you want to plot all the points (the union of the sets). The union is easy:
plot "<paste A B" u 1:($2-$4) w points ls 1,\
"<paste A B" u 3:($2-$4) w points ls 1
The intersection is hard using only unix commandline tools (especially if you want to preserve the order of your input)
using Python though, it's not too bad...
#joinfiles.py
import sys
f1=sys.argv[1]
f2=sys.argv[2]
xA,yA=zip(*[map(float,line.split()) for line in f1.readlines()])
xB,yB=zip(*[map(float,line.split()) for line in f2.readlines()])
f1.close()
f2.close()
for i,x in enumerate(xA):
if(x in xB):
sys.stdout.write('%f %f %f\n'%(x,yA[i],yB[i]))
and then from gnuplot:
plot "<python joinfiles.py A B" u 1:($2-$3) #...