glob does not recognize filename with square brackets

The builtin glob function splits patterns at whitespace. So you are doing something equivalent to

my @files = (
  glob("/home/user/Downloads/folder"),
  glob("name"),
  glob("[www.website.com]/*"),
);

Escaping the whitespace and the brackets would be one option. But it is better to use the core File::Glob module for finer control:

use File::Glob ':bsd_glob';

my @files = bsd_glob("/home/user/Downloads/folder name \\[www.website.com\\]/*");

Now, only the brackets need to be escaped. This also overrides the builtin glob, so you don't actually have to change your code except for that one import (and of course, the pattern).

Tags:

Perl