To my eyes this looks more complex than merlyn's example.
You can't do it this way since you need to know the total number of tests before the tests are run so Test::Builder can output an appropriate test header.
Snippets of code should be wrapped in
<code> tags not<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).