A better solution is to use readdir() instead (or File::Find if you ever want to do it recursively):
my $dir = "C:\\SomeFiles"; my @flist; opendir(my $dh, "$dir"$dir) || die "$!"; while (my $file = readdir($dh)) { if ($_$file =~ /.*(\\.txt)$txt$/i) { print $file; $file . "\n"; my $txt = do { local $/ = undef; open(my $ff, "<", "$dir\\$file") || die "$!"; <$ff>; }; print substr($txt, 0, 100); . "\n"; } } closedir($dh);