Well, I did come up with this, but it may not be any more efficient than what you had and might even be less efficient, you would have to benchmark both codes to know which is really better.
Code:
my %files = map {/^(\w+).\d{6}\.csv$/; $_ => $1} <*.csv>;
print Dumper \%files;
foreach my $file (keys %files) {
open(FH, $file) || die("Error: Cannot open file $file for reading.");
while (<FH>) {
print "$files{$file} $_\n";
}
close(FH);
}
this regexp probably needs refining:
/^(\w+).\d{6}\.csv$/
what is the dot in there for after (\w+)?