our %xmlopt = ( keep_spaces => 1, comments => "drop", ); binmode STDOUT, ":encoding(iso-8859-2)"; if (1) { my $n; my $tw; my $la_handler = sub { my($tw1, $la) = @_; if ($n++ < 2) { print "In the handler for la elements. So far, the document tree contains this: (((\n" . $tw->sprint . "\n)))\n"; } 1; }; $tw = XML::Twig->new( twig_handlers => {"la" => $la_handler}, %xmlopt, ); $tw->parse($doc); }