in reply to pattern match operator

There's a typo in: if($_ =- m/$pat/g)

The =- should be =~.

Ps: From now on, wrap your code in <code> tags. See Writeup Formatting Tips,