use strict; use warnings; use XML::Twig; my $xml = < tag 1 data tag 2 data XML my $root = XML::Twig->new ( twig_handlers => { tag1 => \&process1, tag2 => \&process2, } ); $root->parse ($xml); sub process1 { print "Process1: " . $_->children_text () . "\n"; } sub process2 { print "Process2: " . $_->children_text () . "\n"; } #### Process1: tag 1 data Process2: tag 2 data