PHP versus Perl comparison

December 26th, 2002

by Stephan Spencer

We recommend writing web scripts in PHP, not CGI / Perl. PHP is much better suited to the Web and takes less “overhead,” meaning that scripts will run faster and the server will be able to handle more simultaneous users on your site. Here’s Why…

Perl (Practical Extraction and Reporting Language) is a great language for some things, just not for programming web pages. Perl is indeed “mature” in that it’s been around for a long time, prior to the Web in fact. But that doesn’t mean it’s the most suitable tool for web development. Indeed it’s not. We know this first hand because we used to code web sites in Perl in Netconcepts’ early days (1995 & 1996). In fact, we were honored with a case study in the book “Using CGI” (published by Que) back in 1995 because we were so ahead of the game in regards to building dynamic database-driven web sites. We were the only case study in that book and had 2 full pages devoted to profiling some of our work. But I digress…. 😉

I should preface all this by saying: PHP owes a lot to Perl. PHP was first prototyped using Perl. PHP still shows traces of its Perl ancestry in its string manipulation features.

BUT, Perl has a lot of deficiencies compared to PHP. I’ll highlight the main ones:

PHP is built from the ground-up with database functionality built in, particularly MySQL functionality. Perl is not.

PHP code gets embedded into HTML pages, unlike Perl. This makes it very fast to code web pages and fast to deploy a new site, thus speeding up Web development and lowering overall cost of ownership. An important code management technique for programmers is separating code from data. This allows us to make changes to the code or data without affecting the other. PHP uses the tags to indicate “code inside”. In Perl, however, programmers are encouraged to use print statements to generate the HTML. True it is possible to implement templates in Perl (with more difficulty than in PHP) to separate code and HTML, but 90% of sample Perl code on the web doesn’t do that. PHP is secure. Perl scripts tend to have more security holes. This is because PHP has built-in a lot of the internal operations of dealing with web page requests and serving information.

steroids for sale

PHP is easy to learn in comparison to Perl. It’s easier to learn than C, Python, Java, and most other programming languages used in web development, for that matter. The Perl style of programming is unique, and thus not universally applicable to or from other programming languages. Accessing web form variables in PHP is straightforward, but in Perl requires either detailed knowledge of either HTTP header formats or one of many Perl CGI libraries. PHP takes less “overhead” than Perl, meaning that PHP scripts will run faster than CGI scripts written in Perl, and you’ll be able to handle more simultaneous users on your site. Benchmarking tests show time and again that PHP runs faster than other web programming languages. Check out these benchmarking analyses done by major computing magazines.

PHP code tends to be more consistent and modular than Perl. Don’t just take my word for it. Webmasters are switching to PHP in droves. In fact, PHP has now become the most popular server side language for writing dynamic web pages. More popular Microsoft’s ASP (Active Server Pages), JSP (Java Server Pages), Macromedia’s Cold Fusion, and Perl. PHP is being used by over nine million web sites, that’s over 24% of the sites on the Internet, thanks largely to the benefits outlined above, such as quicker response time, improved security, and transparency to the end user.

(Note that a lot of the above reasoning also applies to why we’ve chosen PHP over ASP, Cold Fusion, etc.)



  1. Perl was old hat in 1999!

    And actually it works just fine for the BBC!

  2. SEO Pakistan says:

    This is exactly what I was trying to find for a customer… Great comparison!

  3. Peter says:

    I so much disagree… PHP safer than Perl? How many security holes a week show up in PHP, and how many show up in Perl? Exactly. A lot versus basically none.

    “PHP has internal operations…”. Perl, just like PHP, needs programming to make things safer, such as input validation. PHP doesn’t do any of this automatically, and neither does Perl.

    The ability to embed PHP within HTML is great, however, most PHP programmers embed PHP into a bunch of pages as part of their application, making theming and customization more difficult. Perl programmers however do it the other way around. Perl code reads templates with HTML in it, parse it, and then present it. Thus we use only one template.

    As for the speed thing. PHP has one major problem that most people ignore: it can be embedded within the web server (i.e. Apache) as a module. Load a PHP application with a lot of traffic and you will see how bloated the web server gets and how loaded the server becomes. I run PHP as a CGI to avoid this problem. As for Perl, if you are concerned about the compilation time on execution (which is the same process as in PHP unless you use a caching system such as Zend or APC), use PersistentPerl (pperl) and the problem is solved.

  4. PHP vs Perl a very interesting question and one in which I have to disagree with the article author. Perl is as you said the origionator of the server side language and as such PHP owes a great deal.

    Over the last 6 years I have learnt both Perl, PHP and ASP. There is many pros and cons to each language. However Perl is the winner in both mine and my staff’s eyes.

    As for the age old question ‘which is faster?’ It is a valid opinion that PHP is faster but Perl.


    Perl has been around longer and there for there is more documentation and solutions to problems. Secondly Perl is more versatile and more secure as the previous person pointed out there is a security hole appearing once a week in PHP where as Perl is far less prone to this sort of problem.

    As for the comment about its easier to learn I dont think thats true. I started my programming days as a Visual Basic 5/6 and progressed to Visual Basic .NET. From this I tried to learn PHP and Perl and found Perl easier to take on board. It wasnt until I had learnt Perl that I learnt PHP afterwards.

  5. James Pearce says:

    As a software developer turned network administrator, I think the benefits of the language depend a lot on the nature of the problem environment.

    In a Windows environment, I tend to use .NET for everything because the API hooks are there. In a Linux / BSD environment, I tend to use Perl because, as pointed out, it is very mature and well documented. There are also many libraries available that make it flexible, more so than PHP. For web interfaces, I tend to use PHP *because* of the ability to easily write HTML and PHP code top to bottom – making RAD easier for me.

    Were I were to write an actual web application, I would probably prefer PHP which would be faster *for me*. This is simply because I’m familiar with it. If I were to write the same application in Perl, I don’t believe I would be able to optimize it as well given the same time frame.

    Thus, I think the question of what language is faster depends on what you and your staff are most familiar with in terms of the problem domain.

  6. by James Pearce — July 13, 2008 @ 10:41 am