use XML::XPath; use XML::XPath::XMLParser; my $xp = XML::XPath->new(filename => 'monks.xml'); my $nodeset = $xp->find('/monk/say/text()'); # what the monks say foreach my $node ($nodeset->get_nodelist) { $_ = XML::XPath::XMLParser::as_string($node); print "$_\n" if(/FOO/); }