in reply to Speed consideration

I would also recommend something like HTML::Template (or Template Toolkit) if you want to do some complex calculations/checking. But some of this can be done in SSI pretty simply. e.g.:
<A HREF='<!--#if expr="$QUERY_STRING" - +-><!--#echo var="QUERY_STRING" --><!--#else -->50<!--#endif -->">Link +</A>
You can also use SSI to check to make sure that the query string matches a specific regular expression, etc. See for more info.