if( my $link_config= $elt->first_child('LINK_CONFIG')) { my $relationship= $link_config->first_child('RELATIONSHIP')->text; # ... } else { warn "no LINK_CONFIG found\n"; # or any other processing necessary }