Skip navigation.
Home
Your source for Perl tips, howto's, faq and tutorials
( categories: )

Perl support similar pattern matching using wildcard operators like unix (and DOS) shells do; you have to enclose the pattern matching between "<>".

FILE PATTERN MATCHING OPERATORS

* match zero or more characters
? match any single character
{expr2,expr2,...exprN}   match expr1 OR expr2 OR ... exprN
[...] match any single character specified within the square brackets
[!...] match any single character except those specified within brackets



Note:
These wildcard operators are also used on regular expressions but the meaning is different when they are used in regular expressions (for example, "too?" matches "too" and "to" in a regular expression context, in a file pattern matching context it matches "tool" but doesn't match "too" or "to").

Examples:

#-- get all files ending in .pl
@list = <*.pl>;
 
#-- get all files ending in .c or .h
@list = <*.[ch]>;
 
#-- files ending in .rpm or .gz
@list = <*.{rpm,gz}>;
 
#-- files begining with a number
@list = <[0-9]*>;