my $dom = $parser->parse_string(book.xml); my $root = $dom->documentElement(); my $xpc = XML::LibXML::XPathContext->new($root); $xpc->registerNs('book', 'http://api.iop.org/Book/1.0/'); $xpc->registerNs('xlink', 'http://www.w3.org/1999/xlink'); foreach my $chapter_node ($xpc->findnodes('/book:bookResource/book:book/book:meta | /book:bookResource/book:book/book:contents/book:chapter')) { foreach my $col(qw/Chapter_Id Chapter_Title Book_Id Book_Publisher Book_Platform Chapter_Doi_Prefix Chapter_Doi Chapter_Id/) { print $xpc->findvalue($chapter_columns{$col}, $chapter_node); } }