An interesting proposition. If you truly need to parse any SQL statement, then it seems to me that you may(?) need to obtain (from the web) an actual, authoritative BNF grammar for the SQL dialect that you are using, then employ a Lex/Yacc style parser using it. Which I can see that Perl can do, although I have not personally used that parser with Perl. I can’t yet speak for Marpa, although it looks interesting and possibly applicable too. I do not know, but certainly would like to know, if there are any Perl modules out there with this degree of rigor and completeness.
The difficulty that I foresee is having to compare two statements by comparing two AST parse-trees, which I do think that you would have to do instead of trying to “un-parse” them back to a then-comparable string.