---
name: "File::FnMatch"
section: "3pm"
platform: "linux"
package: "libfile-fnmatch-perl"
version: "0.02-3+b4"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/File::FnMatch"
---

# File::FnMatch(3pm)

simple filename and pathname matching

## NAME

File::FnMatch - simple filename and pathname matching

## SYNOPSIS

```
  use File::FnMatch qw(:fnmatch);    # import everything
  # shell-style: match "/a/bc", but not "/a/.bc" nor "/a/b/c"
  fnmatch("/a/*", $fn, FNM_PATHNAME|FNM_PERIOD);
  # find our A- executables only
  grep { fnmatch("A-*.exe", $_) } readdir SOMEDIR;
```

## DESCRIPTION

**File::FnMatch::fnmatch()** provides simple, shell-like pattern matching.

Though considerably less powerful than regular expressions, shell patterns are nonetheless useful and familiar to a large audience of end-users.

### Functions

- fnmatch ( PATTERN, STRING \[, FLAGS\] )

  Returns true if *PATTERN* matches *STRING*, undef otherwise.  *FLAGS* may be the bitwise OR'ing of any supported FNM\_\* constants (see below).

### Constants

- FNM\_NOESCAPE

  Do not treat a backslash ('\\') in *PATTERN* specially.  Otherwise, a backslash escapes the following character.

- FNM\_PATHNAME

  Prohibit wildcards from matching a slash ('/').

- FNM\_PERIOD

  Prohibit wildcards from matching a period ('.') at the start of a string and, if FNM\_PATHNAME is also given, immediately after a slash.

Other possibilities include at least FNM\_CASEFOLD (compare `"qr//i"`), FNM\_LEADING\_DIR to restrict matching to everything before the first '/', FNM\_FILE\_NAME as a synonym for FNM\_PATHNAME, and the rather more exotic FNM\_EXTMATCH.  Consult your system documentation for details.

### EXPORT

None by default.  The export tag `":fnmatch"` exports the fnmatch function and all available FNM\_\* constants.

## PATTERN SYNTAX

Wildcards are the question mark ('?') to match any single character and the asterisk ('\*') to match zero or more characters.  FNM\_PATHNAME and FNM\_PERIOD restrict the scope of the wildcards, notably supporting the UNIX convention of concealing "dotfiles":

Bracket expressions, enclosed by '\[' and '\]', match any of a set of characters specified explicitly (`"[abcdef]"`), as a range (`"[a-f0-9]"`), or as the combination these (`"[a-f0-9XYZ]"`).  Additionally, many implementations support named character classes such as `"[[:xdigit:]]"`.  Character sets may be negated with an initial '!' (`"[![:space:]]"`).

Locale influences the meaning of **fnmatch()** patterns.

## CAVEATS

Most UNIX-like systems provide an fnmatch implementation.  This module will not work on platforms lacking an implementation, most notably Win32.

## SEE ALSO

File::Glob, POSIX::setlocale, [**fnmatch**(3)](/fnmatch/3.md)

## AUTHOR

Michael J. Pomraning

Please report bugs to \<mjp-perl AT pilcrow.madison.wi.us\>

## COPYRIGHT AND LICENSE

Copyright 2005 by Michael J. Pomraning

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
