I believe the suggestion was to use Template Toolkit to generate the SQL, not HTML. Another approach is to use a SQL builder. For simple things, SQL::Abstract can work. For complicated things, SQL::Interpolate or Rose::DB::Object::QueryBuilder are better.