Trigger code if object is touching only a PART of another object

Hey yall, I have a game with two squares in it.

One square has a red line on one side.

I want to make it so that if a square touches the red line part of a different square (not any other part) it will damage the square.

How should I accomplish this?

By your description in each case from my image
It would count as successful detection

If the red lines are the only places you check for collision, then use 2 custom collision masks for them: