#!perl -l use strict; use warnings; use XML::XPath; my $xp = XML::XPath->new("xml" => do { undef $/; }); my $path = q{//userprop[nameprop='Version' and valueprop='v1.3']/ancestor::file}; my $nodes = $xp->find($path); for my $node ($nodes->get_nodelist) { print XML::XPath::XMLParser::as_string($node); } __DATA__ test.doc v1.3 Version test.doc Version v1.4