in reply to how to use regexes in SELECT statement
You are mixing Perl code into your Database SELECT statement. That is not going to work at all. If you want to use regular expression in your MySQL statement then you should look here.