Tainted has nothing to do whether regexes match or not. I expect the variables either don't contain what you expect, or $test2 contains one or more characters that are special to the regular expression engine.
Do you have an example of a $test and a $test2 that you expect to match, but don't?