Simple code golf challenge: Character patterns!
Perl 5, 85 bytes

Saved 40 bytes thanks to Peter Taylor's suggestion! (see my older version bellow to see the differences)

83 bytes of code + -pl flag.



s/./$h{$&amp;}?"\\$h{$&amp;}":($h{$&amp;}=$.,join("",map"(?!\\$_)",1..$.++)."(.)")/ge;$_=&lt;&gt;=~$_


Try it online!

XYXYZ is transformed into ((?!\1).)((?!\1)(?!\2).)\1\2((?!\1)(?!\2)(?!\3).) (yup, some of the tests can't be true, but it's shorter that way), and the second input is then checked against that regex. (see the explanations of my older version to get more intuition of how it works)



My older version:
Thanks to Arnauld for pointing out a mistake I made in my first version.
113 bytes of code + -pl flags, and -Mre=eval.

s/./$h{$&amp;}?"\\$h{$&amp;}":($h{$&amp;}=++$i,"(.)")/ge;$_.='(?{++$c;$\=1if!grep$v{$c}{${$_}}++,1..'.(keys%h).'})^';&lt;&gt;=~$_}{


Try it online!

On the example XYXYZ: the first regex will convert the pattern to (.)(.)\1\2(.), and add at the end a test to check if $1, $2 and $3 are different: if so, $\ is set to one. Then, the second input is testes against this regex, and $\ is implicitely printed at the end.
The regex generated for XYXYZ is (.)(.)\1\2(.)(?{++$c;$\=1if!grep{$v{$c}{${$_}}++}1..3})^.
(I'll to add a bit more details to the explanations when I have a moment)