use strict; use XML::Twig; use subs qw(say); my $twig = XML::Twig->new( twig_handlers => { head => \&head, para => \¶, } )->parsefile("foo.xml"); exit; sub head { my ($t, $e) = @_; say '

'.$e->text.'

'; } sub para { my ($t, $e) = @_; process_children($t, $e); } sub list { my ($t, $e) = @_; say '
    '; process_children($t, $e); say '
'; } sub item { my ($t, $e) = @_; say '
  • '.$e->text.'
  • '; } sub process_children { my ($t, $e) = @_; map { if ($_->is_text()) { say $_->text; } else { &{\&{$_->gi}}($t, $_) if exists &{$_->gi}; } } $e->children(); } sub say { return print 'TX ', @_, "\n"; }