Not knowing the full size of the data set this might be overkill, but...
It looks like you can start a hash for each vhost you see, and stick the name of it in $vh or whatever. Then if you see "NO VIRTUAL" simply delete the hash and go on to the next line. In the hash itself you would collect the data elements for each VTD in its own hash. When you see the next vhost tag push the hash you just build onto an array of hashref. Once you see the end of the data ("__DISCARD__") break out of the loop and loop through the array, formating and printing or processing as desired.
You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.