my $validator = XML::LibXML->new(); $validator->validation(1); #test if the XML is well formed: my $doc; eval { $doc = $validator->parse_string($theXML); }; if ($@) { # it's not well formed, your error handling code here... } #test if the XML conforms to the DTD: eval { $doc->validate(); }; if ($@) { # it doesn't conform, your error code handling here... }