Not sure if I understand your question correctly, but I would start with:
- chomp $date; , or better:
- build $date without shelling out (e.g. POSIX::strftime or localtime and sprintf)
- using a correct regular expression, e.g. if ($file =~ m/AAAA\*.*?$date/) { ... }
Update: Missed, that there is a literal * in the filename. \$ matches literal $, not $date.
Non-greedy matching is probably not necessary here, but does no harm (in response to question below). It would be a good idea to also anchor the regexp.
- (also add usestrict; and use warnings; if not already done so)
HTH