If $A$ and $B$ are rectangular, then they can't possibly have inverses, so the premise doesn't hold. However, assuming that $A$ and $B$ were square, then:
$X = ALA^{-1} = BMB^{-1} = Y$ is what we're working with.
Then,
$ALA^{-1} = BMB^{-1}$
$ALA^{-1}A = AL = BMB^{-1}A$
$ALL^{-1} = A = BMB^{-1}AL^{-1}$ This only works if all the elements on the diagonal are non-zero. If so, then $L$ is invertible.
$A = BMB^{-1}AL^{-1}$, which is the closest you're going to get. Again, this assumes that that $A$ and $B$ are both square, because they can't have inverses if they're rectangular, and $L$ must be non-zero for every diagonal entry.
Granted, this isn't explicit, but I believe it is the closest you will get.