It sounds like something you could produce with SQL::Parser, SQL::Statement, or similar modules. I'm not sure they can handle the T-SQL dialect, though.
Also, there's an article on Perl.com on lexing SQL statements, Lexing your data, which is something simpler than parsing... but, it might be enough.
Comment on Re: Modules for T-SQL summary statistics