#!/usr/bin/perl -w #use CGI; # you should be using CGI.pm #use strict 'nuff said use strict; #You should factor out the directory name since you are using it in multiple places; my $HOMEDIR = '.'; #you should put the name of the file and a newline for errors (much easier to understand) #you should avoid '||', use 'or' instead. 'or' will be what want most of the time. # FYI '||' binds tighter than 'or; opendir(HOMEDIR, "$HOMEDIR") or die ("Unable to open directory $HOMEDIR\n"); my @files = grep !/^\./, readdir(HOMEDIR); closedir(HOMEDIR); #You should learn to use $_, saves loads of typing foreach (reverse sort @files) { #check to see if it is actually a file (you don't want directories) next if (!(-f "$HOMEDIR/$_")); print "--->$_<---\n"; #same as above open(STUFF, "./$_") or die ("Unable to open file $_\n"); while() { 1 .. 5 ? print: last; } close (STUFF); print "\n"; }