The
Subs
Style
For each start tag, calls a subroutine whose name is the element type
For each end tag, calls a subroutine whose name is the element type with an "_" on the end
use XML::Parser;
$xml = "<z a1='v1'> a <x> b <x2> c </x2> d </x> e <y> f </y> g </z>";
$p = new XML::Parser( Style => 'subs' );
$p->parse($xml);
sub x { print "yep, saw <x>\n"; }
sub x_ { print "yep, saw </x>\n"; }
yep, saw <x>
yep, saw </x>