You can stream it and prevent memory hogs on big data. Additionally, install Text::CSV_XS for speed
use Text::CSV_XS "csv";
Install Text::CSV_XS, yes, but don't explicitly use Text::CSV_XS. Text::CSV is smart enough to pull in the XS version if installed, and will fall back to pure Perl if not. There is usually no point in having the script break if XS isn't available.
perl -MText::CSV -e 'print Text::CSV->module'
I agree with your streaming suggestion. I had opted to keep my example simple given the 20k line input. Good to teach the streaming approach, though. ++
use strict; use warnings; omitted for brevity.