in reply to need to optimize my sub routine
my $csv = Text::CSV_XS->new;
You can move this outside of your loop. You only need to create it once.
Also, I don't think re-writing this in C will gain you much. You'll just be re-implementing a lot of what perl already does and you'll have to spend the time to debug and verify it. The code as it stands is very readable and maintainable. If you need a factor of 2 (or even 3 or 4) speed up, just run the process in parallel on another box. It'll be less work for you and a lot more cost effective for your company even if they have to buy more hardware.
Another option is to process the files incrementally as they are generated (if you're not already doing this.)
|
|---|