http://www.perlmonks.org?node_id=15179

Zoogie has asked for the wisdom of the Perl Monks concerning the following question:

I need to get a list of files that fit a set of filename globs input by the user. The problem is, the files may be in a different directory. For example, if the user enters:

  $area = "public/test/";
  @files = ("*.txt", "_*");
The function should return something like:
  readme.txt, files.txt, _index, _sortopts, ... etc.
I'm trying to use the glob function, but if you specify another directory, that directory name is prepended to every filename. Here's my current function:

@file_list =
    map { /^$area(.*)/; $1 }
    glob(join(' ',map { $area.$_ } @files));
Works as expected, but that seems like a lot more work than necessary. Is there an easier / clearer / more efficient way to do this?