The error seems to be emanating from SQL::Parser - which looks like it is getting confused by the complex SQL syntax.
in reply to Error "'exists ^0^' has chars not alphanumeric or underscore in perl"
Try re-designing your SQL statement using UNION or INTERSECTION - maybe that will get past the Parser.
Sorry - I'm not a SQL guru, and dont know the syntax well enough to actually provide the alternative.
BTW - your attempt to clear the SQL of funny characters has a bug - it deletes the "%" after "Data%" - leading to potentially undesirable results.
The SQL string shown is clean to start with - it does not need the regex you have attempted to use.
Most people believe that if it ain't broke, don't fix it.
Engineers believe that if it ain't broke, it doesn't have enough features yet.