Text::Glob(3) User Contributed Perl Documentation Text::Glob(3)

# [NAME](#NAME)

Text::Glob - match globbing patterns against text

# [SYNOPSIS](#SYNOPSIS)

```
 use Text::Glob qw( match_glob glob_to_regex );
 print "matched\n" if match_glob( "foo.*", "foo.bar" );
 # prints foo.bar and foo.baz
 my $regex = glob_to_regex( "foo.*" );
 for ( qw( foo.bar foo.baz foo bar ) ) {
     print "matched: $_\n" if /$regex/;
 }
```

# [DESCRIPTION](#DESCRIPTION)

Text::Glob implements [**glob**(3)](/man/os/perl-text-glob/glob.3) style matching that can be used to match against text, rather than fetching names from a filesystem. If you want to do full file globbing use the File::Glob module instead.

## [Routines](#Routines)

[match\_glob( $glob, @things\_to\_test )](#match_glob%28)

Returns the list of things which match the glob from the source list.

[glob\_to\_regex( $glob )](#glob_to_regex%28)

Returns a compiled regex which is the equivalent of the globbing pattern.

[glob\_to\_regex\_string( $glob )](#glob_to_regex_string%28)

Returns a regex string which is the equivalent of the globbing pattern.

# [SYNTAX](#SYNTAX)

The following metacharacters and rules are respected.

"\*" - match zero or more characters

"a\*" matches "a", "aa", "aaaa" and many many more.

"?" - match exactly one character

"a?" matches "aa", but not "a", or "aaa"

[Character sets/ranges](#Character)

"example.\[ch]" matches "example.c" and "example.h"

"demo.\[a-c]" matches "demo.a", "demo.b", and "demo.c"

[alternation](#alternation)

"example.{foo,bar,baz}" matches "example.foo", "example.bar", and "example.baz"

[leading . must be explicitly matched](#leading)

"\*.foo" does not match ".bar.foo". For this you must either specify the leading . in the glob pattern (".\*.foo"), or set $Text::Glob::strict\_leading\_dot to a false value while compiling the regex.

"\*" and "?" do not match the seperator (i.e. do not match "/")

"\*.foo" does not match "bar/baz.foo". For this you must either explicitly match the / in the glob ("\*/\*.foo"), or set $Text::Glob::strict\_wildcard\_slash to a false value while compiling the regex, or change the seperator that Text::Glob uses by setting $Text::Glob::seperator to an alternative value while compiling the the regex.

# [BUGS](#BUGS)

The code uses qr// to produce compiled regexes, therefore this module requires perl version 5.005\_03 or newer.

# [AUTHOR](#AUTHOR)

Richard Clamp &lt;richardc@unixbeard.net&gt;

# [COPYRIGHT](#COPYRIGHT)

Copyright (C) 2002, 2003, 2006, 2007 Richard Clamp. All Rights Reserved.

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

# [SEE ALSO](#SEE_ALSO)

File::Glob, [**glob**(3)](/man/os/perl-text-glob/glob.3)

2026-08-26 perl v5.44.0

---

Document: Text::Glob(3pm) from perl-text-glob 0.11-r1 (Chainguard OS)
Source: https://cpan.metacpan.org/authors/id/R/RC/RCLAMP/Text-Glob-0.11.tar.gz
