#!perl use strict; use XML::Twig::XPath; my $twig = XML::Twig::XPath->new(); $twig->parsefile('txlife.xml'); my $root = $twig->root; my $xpath = q!//Party[@id=//Relation[child::RelationRoleCode[@tc='37']]/@RelatedObjectID]/Producer/CarrierAppointment/CompanyProducerID!; my @nodes = $root->findnodes($xpath); for (@nodes){ print $_->text; }