in reply to Checking files in a directory

Instead of testing for the directory existance, just add error checking to your chdir.

Additionally, your opendir error check will never be utilized because you used || instead of or.

I'd also recommend that you use a lexical directory handle instead of a glob.

chdir $directory or die "Can't cd to $directory: $!"; opendir my $dh, '.' or die "Can't open $directory: $!"; while (my $file = readdir $dh) { print "$file\n"; } closedir $dh;

Within your loop, are you trying to match files that begin with the literal $filemask? If so, then you'll want to escape that using quotemeta or \Q...\E.

And as ww pointed out, I don't think you need the bareword chomp.

Don't know what $Mode is about...

if ( $file =~ /^\Q$filemask\E/i ) { push @chk_files, $file; print "\n\t$file "; } # End of IF

And finally, be sure to have use strict and use warnings turned on.