in reply to There is more than one way (and mine is not the best)

If your code is being run in the same directory as the files you could always do something like this:

while (<*txt>) { # process the file ($_ will contain the name of the file) }

This would remove the need for the "qcode" file, since it's only doing what the file system already does---namely, maintain a list of file names.

As for the rest of the code: I think you're missing some braces in various places. If you tried to run your code through a good indenting text editor, you would notice that things are not lining up as you would expect. Also, doing a perl -cw ./yourprogram.pl says there are syntax errors with your script.

Finally, I'm not sure why you're processing the file twice. I'm assuming there is a good reason, but it's not apparent to me at the moment.