Pattern-sequence memory is very useful when you want to match the same character in several places but don’t care which character you match as long as all occurrences are the same character. For example, the below code matches the date format “dd-mm-yy” where the dashes can be any two of the same non-word characters (in regex notation the range would be [^_0-9a-zA-Z]). Pattern sequences are stored in memory from left to right, so “\1” would represent the first match.
The input file is called “dates.txt” and contains the below data. The Perl script should only print out the three lines of text in the file that meet the regular expression criteria: “12-29-11”, “12.29.11”, and “12 29 11”.
“dates.txt” file input and Perl script output