If you had an array of file names, and did the following: my @grepped = grep /\d{8}\.txt$/ @filenames;
..then your array @grepped would contain the entry 'file1_system_051117123050.txt' if this filename was in the @filenames array.
However, if you want to capture text from a string, then you want a regular expression match: if ( $filename =~ m/(\d{4})\d{4}.txt$/ ) {
print( $1 . "\n" );
}
..if $filename contained 'file1_system_051117123050.txt' then you would have '1712' printed out as that was the four digits captured within parenthesis (curly brackets) in the regular expression match. |