Perl-python regex-performance comparison

Chris Rebert clp2 at
Tue Mar 3 19:32:04 CET 2009

On Tue, Mar 3, 2009 at 9:05 AM, Ivan <ivan at> wrote:
> Hello everyone,
> I know this is not a direct python question, forgive me for that, but
> maybe some of you will still be able to help me. I've been told that
> for my application it would be best to learn a scripting language, so
> I looked around and found perl and python to be the nice. Their syntax
> and "way" is not similar, though.
> So, I was wondering, could any of you please elaborate on the
> following, as to ease my dilemma:
> 1. Although it is all relatively similar, there are differences
> between regexes of these two. Which do you believe is the more
> powerful variant (maybe an example) ?

I would think that either they're currently equal in power or Perl's
are just slightly more powerful, as pretty much all languages have
basically copied Perl's regular expressions almost exactly. If you're
talking about Perl6, then combined with the new "rules" feature it's
much more powerful; however, like Perl's regular expressions, someone
will probably write a library like pcre that implements it for all
other languages, so it'll probably just be a matter of syntax.

> 2. They are both interpreted languages, and I can't really be sure how
> they measure in speed. In your opinion, for handling large files,
> which is better ?
> (I'm processing files of numerical data of several hundred mb - let's
> say 200mb - how would python handle file of such size ? As compared to
> perl ?)

They're probably both about the same. Your problem is probably
IO-bound, so the slowness of either language will likely be made
irrelevant by the comparative slowness of your hard disk. If you
really care about maximum speed here, you should probably write a C
extension for the most intensive part of your algorithm (fairly easy
to do with Python, probably about the same with Perl), though Python
also has Psyco and Cython available as other ways to speed up your
program without resorting to C; don't know if Perl has any similar

> 3. This last one is somewhat subjective, but what do you think, in the
> future, which will be more useful. Which, in your (humble) opinion
> "has a future" ?

Python is already well on its way to a smooth transition to Python 3.0
(Python's Perl6 equivalent) with few drastic changes to the language;
most of the changes are pretty incremental but just happen to break
backward compatibility; and the resulting language is still quite
clearly identifiable as Python.
Perl, on the other hand, is currently quagmired in a long,
indeterminate wait for the epic and drastically-revised Perl 6 to be
They both have a future, but Python's definitely appears more secure
at this point. It's more wait-and-see with Perl. But take this with a
grain of salt due to the obvious pro-Python bias you'll get on this


I have a blog:

More information about the Python-list mailing list