use XML::Simple; use strict; use warnings; $| += 1; opendir TMP,'/u1/tmptest'; my @files = grep /xml$/, grep { - r } readdir TMP; chdir '/u1/tmptest'; my $flag = 0; foreach my $file (@files){ my $tmp_xml = XMLin("./$file"); process($tmp_xml); } sub process { my $xml = shift; my $title = $xml->{head}->{title}; .... }