in reply to XML::LibXML memory leak
Use XML::Twig or XML::Rules and process the file in chunks. By the time your loop runs it'a already too late and the memory has already been wasted.
Jenda Enoch was right! Enjoy the last years of Rome.