You treat regex as that of a conventional if statement with $1 and $2. The proper format of regex is: > if ($regex($1,/^MatchString$/)) { with the delimiters (forward slashes). And to reference to the match string, you enclose it with a set of parenthesis and use $regml(1). Like Meta said, the use of regex is rather pointless in the case of your code.