As for rolling your own parser you can look into HTML::TokeParser or HTML::Parser. They will save you from having to deal with the actuall parsing of tags.
Disclaimer: I haven't actually tried either of these with SSI tags so i dont if there are any pitfalls