Why are you using backticks for something that perl can do perfectly fine on its own?
my @files = grep !-d, <$dir/*>;
Btw, your error is that $'
is a perl predefined variable (postmatch) that gets interpolated, so the closing '
is missing.
If you had used
use strict;
use warnings;
Perl would have told you what the problem was:
Use of uninitialized value $' in quoted execution (``, qx) at ...
Always use those two pragmas: Errors do not get less difficult to handle because you don't know about them.