my $xp = XML::XPath->new(filename => $file); $plantdata->{nodeset} = $xp->find('//loop_device[@loop_number="1"]'); #### foreach my $device ($plantdata->{nodeset}->get_nodelist()) { $devicename = find('devicename')->string_value; $devicetype = find('devicetype')->string_value; do more stuff } #### if ($devicetype eq "complex") { $seachstring = sprintf "//loop_device[@devicename=\"%s\"]/subdevice", $devicename; $subdevice = $xp->find($searchstring); } #### $subdevice = $device->find('/subdevice');