if (1) { my $line_handler = sub { my($tw1, $li) = @_; print "In the line handler. Full line is (((" . $li->sprint . ")))\n"; for my $la ($li->findnodes("//la")) { my $t = $la->text; my $ta = $la->next_sibling_text; print "Found an la element. Its text is ((($t))). The text immediately after is (($ta))).\n"; } $tw1->purge; }; my $tw = XML::Twig->new( twig_handlers => {"line" => $line_handler}, %xmlopt ); $tw->parse($doc); }