use XML::XPath; my ($xml, $xp); $xml = “not xml”; eval { $xp = XML::XPath->new(xml => $xml); }; if ($@) { print “Parsing failed\n”; } …..