in reply to Cannot open file within a loop

Hello ic23oluk

The current directory does not change when you open a folder handle, and I suspect that use warnings; must warn about this.

Your open (READ, "$file") || die "Cannot open $file: $!.\n"; must be changed into open my $readfh,'<', $dir.'/'.$file or die "Cannot open $dir.'/'.$file: $!.\n";

You can check if I'm right testing the file for existence just before trying to open it: warn "File [$file] not found" unless -e $file;

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.