use XML::LibXML; my $doc = XML::LibXML->load_xml(location => '/path/to/file.xml'); my @envdetails = $doc->findnodes('//ENVDETAILS'); for my $envdetail (@envdetails) { my $id = $envdetail->getAttribute('id'); print "id: $id\n"; my $dmgrhost = $envdetail->findvalue('DMGRHOST'); print "DMGRHOST: $dmgrhost\n"; my @nodes = $envdetail->findnodes('NODE'); for my $node (@nodes) { my $nodeid = $node->getAttribute('nodeid'); print "nodeid: $nodeid\n"; my $nodehost = $node->findvalue('NODEHOST'); print "NODEHOST: $nodehost\n"; my @jvms = $node->findnodes('JVM'); for my $jvm (@jvms) { my $jvmtype = $jvm->getAttribute('jvmtype'); if ($jvmtype eq 'api') { my @jvmnames = $jvm->findnodes('JVMNAME'); for my $jvmname (@jvmnames) { my $name = $jvmname->textContent; print "JVMNAME: $name\n"; } } } } } # OUTPUT id: abc DMGRHOST: a.b.c.d nodeid: 1 NODEHOST: v.x.y.z JVMNAME: abc_api1.1 JVMNAME: abc_api1.2