Perl for Text Processing: Still Useful After All These Years
Every few years someone declares Perl dead. And every few weeks I write another Perl one-liner to process text files that would take ten lines in Python. The language has aged, certainly, but for specific tasks it remains unmatched.
The One-Liner Advantage
Perl's command-line mode with the -n, -p, -a, and -e flags turns it into a surgical text-processing tool. Extracting the third column from a tab-separated file, filtering lines matching a pattern, and reformatting the output can happen in a single command. The equivalent Python script requires importing modules, opening files, and writing loops.
Regular expressions are first-class citizens in Perl. They are part of the syntax, not bolted on through a library. Pattern matching, substitution, and capture groups flow naturally. For anyone who thinks in regular expressions, Perl is the most direct translation of thought to code.
Where I Still Use It
Log file processing is the primary use case. Web server logs, application logs, and system logs all benefit from Perl's line-by-line processing model. I have a collection of scripts that extract error patterns, count frequencies, and generate summary reports. They run in cron jobs and have been doing so reliably for years.
Data cleaning before analysis is another common task. CSV files with inconsistent quoting, mixed encodings, and embedded newlines are Perl territory. The Text::CSV module handles edge cases that break simpler parsers.
The Modern Perl Ecosystem
CPAN still works. Modules are still maintained. Perl 5.38 added new features like the try/catch syntax and improved Unicode handling. The language evolves slowly, which is a feature when your scripts need to run for a decade. You may also find dog-friendly travel spots in France helpful.
Mojolicious is a surprisingly good web framework if you need one. DBIx::Class remains the best ORM I have used in any language. And Perl's testing culture, with Test::More and prove, predates and influenced testing practices in other languages.
When Not to Use Perl
New projects with teams should use Python or whatever the team knows. Perl's flexibility is a liability in collaborative environments. The language offers too many ways to do the same thing, and code style varies wildly between programmers.
Machine learning and modern data science have no meaningful Perl ecosystem. Do not try. Use Python or R for those tasks and call Perl for the preprocessing step.
The Perl routines are still ugly text-processing scripts. But they work, and they will keep working long after the next trendy language arrives.