use strict; use warnings; use XML::Twig; my $twig = XML::Twig->new ( twig_handlers => { Preroll => \&handleNode, Midroll => \&handleNode, Postroll => \&handleNode, } ); $twig->parse (do {local $/; }); sub handleNode { my ($tag, $elt) = @_; my $creative = $elt->first_child ('Creative'); print "Creative: ", $creative->text (), "\n"; } __DATA__ #### Preroll_30sec N/A TBD http://192.168.0.1:80/foo/bar null:414 4 Postroll_60sec N/A TBD http://192.168.0.1:80/foo/bar null:418 6 Midroll_45sec_3 N/A TBD http://192.168.0.1:80/foo/bar null:417 5 Midroll_45sec_1 N/A TBD http://192.168.0.1:80/foo/bar null:415 5 Midroll_45sec_2 N/A TBD http://192.168.0.1:80/foo/bar null:416 5 #### Creative: Preroll_30sec Creative: Postroll_60sec Creative: Midroll_45sec_3 Creative: Midroll_45sec_1 Creative: Midroll_45sec_2