#!/usr/bin/perl use strict; use warnings; use XML::Parser; my ( $tagname, $tagtext ); # "globals" used in callback subs my @target_tags = qw(ID TimeStamp IP_Address Title Complainant Contact Address Email); my $target_regex = join( '|', @target_tags ); my $parser = XML::Parser->new( Handlers => { Start => \&get_tagname, Char => \&get_tagtext, End => \&print_tagdata, } ); for my $xmlfile ( <*.xml> ) { $parser->parsefile( $xmlfile ); } sub get_tagname { $tagname = $_[1]; $tagtext = ''; } sub get_tagtext { $tagtext .= $_[1]; } sub print_tagdata { if ( $_[1] =~ /$target_regex/ ) { print "$_[1] = $tagtext\n"; } }