in reply to sub strict refs errors.

It's doing exactly what you told it to do.
return unless -d $dir;
It returns undef if your file is not a directory. I'm assuming H1.txt is a file.

You might want to read about File test operators



grep
Mynd you, mønk bites Kan be pretti nasti...