in reply to Processing xml data in multiple files using XML::Twig and outputting in a file

use warnings; use strict; use XML::Twig; my @array = qw(file1 file2); foreach (@array) { parXML($_); } sub parXML { my $file = shift; #print "$file\n"; my $twig=XML::Twig->new(twig_roots => {IP_ADDRESS => \&ip, COM=>\& +co}); $twig->set_pretty_print('indented'); $twig->parsefile($file); } sub ip { my($twig, $ip)= @_; print "Target:".$ip->text."\n"; $twig->print; $twig->purge; } sub co { my($twig, $co)= @_; $co->print; print "\n\n"; $twig->purge; } __END__ Output to STDOUT: Target:192.168.67.16 <top> <IP_ADDRESS>192.168.67.16</IP_ADDRESS> </top> <COM> <DS> <N>1</N> </DS> </COM> Target:192.168.67.110 <top> <IP_ADDRESS>192.168.67.110</IP_ADDRESS> </top> <COM> <DS> <N>5</N> </DS> </COM>

On a side note, you can probably replace:

@array = `ls file* | awk '{print \$0}'`;
with:
@array = glob 'file*';