in reply to How Do I Skip Spaces At The End of Words Using A Regex?

If you change the pattern match to

if ( $x =~ /\Q$y\E\s+/ig ) { # . . . }
it should work fine.

After Compline,
Zaxo