Is the ZIP code always at the beginning of the filename? You can use the core module File::Basename to strip off the path:
use warnings; use strict; use File::Basename qw/fileparse/; my @files = ( '-/yf/-/22211_01_09_2000_XYz.pdf', '_/gt/-/02239_04_04_1989_PkW.pdf', '-/xy/-/02239_04_04_1989_PkW.pdf' ); for my $file (@files) { my $bn = fileparse($file); my ($zip) = $bn =~ /^(\d{5})\D/; print "$file => $zip\n"; }
In reply to Re: Matching hyphens in file path to extract zip code
by haukex
in thread Matching hyphens in file path to extract zip code
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |