in reply to sub strict refs errors.

return unless -d $dir;

You are checking to see if $dir is a directory, even though you assigned a file to that variable just above it. Presumably HL1.txt is a file, so -d will return false.