Is the $ocontent accumulating throughout the whole parse, or is it occasionally reset, and how big does it get? Maybe XML::Twig (xmltwig.com) would help reduce memory usage (if you can periodically purge what's been parsed so far)? I don't know. I don't know enough about your code or what you're trying to do.