Pattern matching across two different objects

I'm trying to do something in Hazel that I thought would be relatively simple but I haven't been able to figure out how to. Having browsed around the user forum, I now suspect that I need use a script. Specifically, I would like to write a rule that compares part of a file's name to the name of its parent folder and then take an action if they do not match. I have no problem creating custom tokens for the file name substring and for the parent folder name, but I can't figure out how to compare them.
Please advise. Thanks!
Please advise. Thanks!