#!/usr/bin/perl -l use strict; use warnings; use XML::LibXML qw(:all); my $dom = XML::LibXML->load_xml(string => <<'EOT'); Tale of Two Cities EOT foreach my $node ($dom->findnodes('//*')) { print "node name is ", $node->nodeName(); if ($node->hasChildNodes == 0) { print "No children."; } if ($node->textContent) { print "node text is: ", $node->textContent; } }