in reply to directory listing

You could take a look at glob.

Also, you don't need to open the file each time in the loop, do something like that:

open MYFILE, '>', '/tmp/pkgtest' or die "Can't open pkgtest: $!"; for (@array){ print MYFILE, $_, "\n"; } close MYFILE;