my $t = 1; # loop thru array of directory while ($filename = readdir(HOMEDIR)) { #parse the . .. things from directory array and for jpgs only if($filename ne "." && $filename ne ".." && substr($filename,length($filename)-4,4) eq ".jpg") { #increment index my $nfile; # create and print the jpg xml item into xml file $nfile=substr($filename,0,length($filename)-4); print FIL "\n"; } $t++; # loop }