@xmlFileNames=grep !/^\.\.?$/ && /\.xml$/,readdir(DIR); The number of xml you get is the number of total customers. #### foreach my $customer (@xmlFileNames) { $customer =~ s/\.xml//g; system ("/usr/local/bin/unzip ${customer}.zip ${customer}.xml ${customer}.pdf ${customer}.xls"); }