in reply to Catching . .. in file listing

First, your commented if clause would work if you changed your "or" to an "and" - a valid choice must be both not "." and not "..". Also, in regular expressions, . is a wildcard character, so they will match far more than you intend - see perlretut.

If you wanted to avoid some layers of conditional nesting, you could use next as a short circuit on your file tests. Something like:

opendir(GPS,"$new_dir") or die "Cannot open directory"; my @GPS = readdir(GPS); closedir(GPS); foreach my $kid (@GPS){ next if $kid eq "."; next if $kid eq ".."; next if not defined $kid; next if $kid =~ /\.bak$/; next if $kid =~ /\.txt$/; open KID , '<', "$new_dir\\$kid" or die "Open failure on $kid: $!" +; my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ct +ime,$blksize,$blocks) = stat(KID); my $data = <KID>; close KID; if (defined($data)){ my @data = split(" ", $data); my $diff = time-$mtime; if ($diff >= 3600){ unlink($kid); } elsif ($diff >= 20){ } } }

Update: I forgot to mention you should be checking whether open succeeds or not. As well, you may consider checking out the file tests available in -X.