use XML::LibXML; use XML::LibXML::Iterator; my $string = q| Computer Parts .... |; my $doc = XML::LibXML->new->parse_string( $string ); my $iterator = XML::LibXML::Iterator->new( $doc ); my ($path,$value) = ('',''); while ( $iterator->nextNode ) { if ($path and $value) { print "$path $value\n"; ($path,$value) = ('',''); } my $current = $iterator->current; my $type = $current->nodeType; if ( $type == XML_ELEMENT_NODE ) { $path = $current->nodePath; } elsif ( $type == XML_TEXT_NODE ) { my $text = $current->nodeValue; chomp $text; $value = $text if $text; } }