Your program works with files, but Perl's errors and warnings only report the last used filehandle, not the name of the file.
Use the filename as the filehandle:
open($path, "< $path") or die "Couldn't open $path for reading : $!\n";
Ordinarily, error messages say:
The filehandle LOG doesn't help much because you don't know which file the handle was connected to. By using the filename itself as indirect filehandle, Perl produces more informative errors and warnings:
Unfortunately, this doesn't work with