· Puhirek

Finding Perl Underneath a Legacy PHP System

The inventory that started this

In October 2026, two critical vulnerabilities in PHP were disclosed: CVE-2026-109618 and CVE-2026-109619, nicknamed php2shell. Both carry a CVSS v4.0 score of 9.2. Both let an unauthenticated remote attacker execute arbitrary code.

What made that week unpleasant for anyone running servers was where the flaws lived. Not in a framework, not in a library — in the PHP engine itself. Every installation that serves web requests was in scope: PHP-FPM, Apache with mod_php, php-cgi, FrankenPHP, LiteSpeed. PHP considered the risk highest for mod_php, where an unauthenticated request can reach the bug before any application code runs. Fixes shipped on October 21, 2026 as PHP 8.5.12, 8.4.27, 8.3.36 and 8.2.35.

If you are on something older, the picture splits — though in neither case is the answer simply that no patch exists.

Branches from 7.4 through 8.1 got no official release. What the PHP security team published instead was a set of minimal source backports: the fix rewritten against the older code and distributed as source, for people building PHP themselves or running without a vendor's extended support. Note what that does not include — no version bump, no binaries. After applying one, php -v reports exactly what it did before, so any scanner or audit that judges exposure by version string will keep flagging the host.

Branches from 5.4 through 7.3 got nothing upstream, not even that. But upstream is not the only supplier. Distribution and control-panel vendors shipped patched builds well past their own end-of-life this round — Ubuntu Pro's extended maintenance, RHEL, Remi, Plesk, CloudLinux — and a vendor package is usually the better answer anyway, because it stays inside package management instead of being overwritten by the next upgrade. Check what your vendor published before concluding you are stuck.

So, like a lot of people who look after other people's infrastructure, I spent that week taking inventory. Which servers run PHP. Which version. Which SAPI. How quickly each one can be patched, and what breaks if it is.

Working through the oldest systems first, I kept finding something I was not looking for.

There was Perl in them.

Not as a leftover script in /usr/local/bin. Load-bearing Perl. An entire section of one site served by Perl CGI. A CMS — Movable Type — that turned out to be a Perl application. Underneath the PHP layer everyone knew about, there was an older layer nobody had mentioned.

Why a 2026 PHP system has Perl in it

In hindsight this should not have surprised me, and the advisory itself contains the hint.

php-cgi is on the affected list. That execution model — spin up a process, handle one request, exit — is not a modern way to run PHP. It is a survival from the CGI era. Any system still running it was built, or at least designed, when CGI was simply how the web worked.

And in that era, CGI meant Perl. If you needed a contact form, a counter, a search page, or a blog in 1999, you wrote it in Perl or you installed something written in Perl. PHP existed, but it was the newcomer.

So the rule of thumb turns out to be straightforward: a system old enough to still be running php-cgi is old enough to have Perl in it. The two strata were deposited at the same time. Finding one and not the other is the unusual case.

This matters practically. When you inherit a legacy PHP system and audit it for vulnerable code, scanning the .php files tells you about one layer. The .cgi and .pl files are a second codebase, with its own dependencies, its own ancient assumptions, and — as I will come to — its own way of hiding bugs in plain sight.

The connection is not a coincidence

While reading up on all of this, I ran into two facts that reframed the whole thing for me.

The first is sitting in code I write every week. PHP's regular expression functions are the preg_ family: preg_match(), preg_replace(), preg_split(). I had used them for years without once asking what the p was for.

It stands for Perl. The underlying library is PCRE — Perl Compatible Regular Expressions. PHP's regex engine is not merely similar to Perl's; it was built to be compatible with it, because by the mid-1990s Perl's regex syntax was the de facto standard and matching it was the obvious choice.

The second fact is blunter, and it is worth getting the order of events right, because the short version of this story circulates in a form that is slightly wrong.

In 1994 Rasmus Lerdorf was tracking visits to his own online resume using a CGI wrapper he had written in Perl. It did not hold up: his server had to fork a Perl process for every request, and he disliked having to write Perl that printed HTML when what he wanted was templates with logic embedded in them. So he rewrote the tools in C. That C version is what was released publicly in 1995 as Personal Home Page Tools, and the official PHP history accordingly describes the first incarnation of PHP as a set of CGI binaries written in C.

So the accurate claim is not "PHP was written in Perl." It is something nearly as striking: PHP exists because Perl CGI was too expensive to keep running — and the replacement borrowed Perl's syntax anyway. PHP/FI, the next rewrite, had Perl-like variables and a syntax the PHP project itself describes as similar to Perl's, if simpler and less consistent.

"PHP's roots are in Perl" is not an analogy. It is what PHP was built out of, and away from.

What Perl is, briefly

Perl was created in 1987 by Larry Wall as a Unix scripting language for report generation and text manipulation. PHP arrived in 1994–95, which puts Perl roughly seven years ahead — enough of a head start to be the thing PHP borrowed from.

The name is usually given as Practical Extraction and Report Language, though that is a backronym applied after the fact rather than an official expansion. It describes the original job well enough: pull information out of text, reshape it, print it.

Perl was assembled rather than invented. It takes variable declarations, expressions, control structures and subroutines from C; leading symbols like $ and @ and convenience built-ins from shell; hashes from awk; regular expressions from sed; list handling from Lisp. That habit of absorbing whatever already worked is itself one of the things PHP inherited.

It is also worth saying plainly, because the assumption runs the other way: Perl is not abandoned. Stable releases continue on a roughly annual cadence — 5.40.0 in 2024, 5.42.0 in 2025, and the current 5.44.0 on July 15, 2026, which brought Unicode 17 support and named parameters in subroutine signatures. The latter is still experimental: it warns under the experimental::signature_named_parameters category, which use experimental 'signature_named_parameters'; silences, on top of having signatures themselves enabled.

Reading Perl as a PHP developer

Here is the part I did not expect: PHP experience makes Perl easier to start and easier to misread. The two languages look enough alike that you stop paying attention right where you should not.

A minimal script:

#!/usr/bin/perl
use strict;
use warnings;

print "Hello, Puhirek!\n";

Run it with perl hello.pl. No separate build step — you edit the file and run it, which is precisely why Perl won the CGI era, and precisely the property PHP copied. (Perl does compile the whole file before executing any of it, as its error messages will remind you in a moment. What it does not need is a compiler invocation of your own.)

The PHP equivalent is almost the same shape:

<?php
echo "Hello, Puhirek!\n";

print versus echo, and that is the visible difference. Statements end in semicolons in both. \n is interpreted as a newline inside double quotes and left as a literal backslash-n inside single quotes — in both. That double-quote/single-quote distinction is one more thing PHP took from Perl rather than from C.

So far, so comfortable. Now the part that will actually bite you.

Sigils are not decoration

In PHP, every variable starts with $. A string, an array, an object — all $.

<?php
$name = "Puhirek";
$list = ["a", "b", "c"];

In Perl, the leading symbol changes with the kind of value:

my $name = "Puhirek";        # scalar — a single value
my @list = ("a", "b", "c");  # array
my %hash = (key => "value"); # hash — associative array

These symbols are called sigils. PHP kept $ and dropped the other two as sigils. (PHP does have an @, but it is the error-suppression operator — an entirely different thing.) That decision is one of the real forks between the two languages, and it is why PHP's single array type has to do the work that Perl splits between @ and %.

The trap

Knowing the sigils is not enough, because of this:

#!/usr/bin/perl
use strict;
use warnings;

my @list = ("a", "b", "c");
print @list[0];

With PHP reflexes, that reads as "element 0 of the array @list". And the genuinely nasty part: it prints a. You move on.

The correct form is:

my @list = ("a", "b", "c");
print $list[0];   # a

The array as a whole is @list, but a single element extracted from it is a scalar, so it takes $. The sigil describes the value you are pulling out, not the name of the container.

So what was @list[0]? It is an array slice — a different construct that extracts elements as a list:

my @list = ("a", "b", "c");
print @list[0, 2];   # ac

@list[0] is a one-element slice. It happens to produce the same visible output as the thing you meant, which is exactly why the mistake survives.

Which is why those two lines are not optional

With use warnings; in place, Perl tells you:

Scalar value @list[0] better written as $list[0] at hello.pl line 6.
a

It names the mistake precisely. Drop that one line and Perl prints a and says nothing, forever.

  • use strict; forbids using variables you never declared
  • use warnings; flags constructs that are legal but probably not what you meant

This is also a useful triage signal when you inherit someone else's code. Check whether an old CGI script opens with use strict;. Plenty do not. In those files, undeclared variables appear from nowhere and the same name is shared across the entire script. How carefully you need to read the next 500 lines depends a great deal on whether that one line is present.

Syntax errors point one line too far

One more practical note. Omit a semicolon:

#!/usr/bin/perl
use strict;
use warnings;

print "Hello, Puhirek!\n"
print "Hello World\n";
syntax error at hello.pl line 6, near "print"
Execution of hello.pl aborted due to compilation errors.

The missing semicolon is on line 5. The error says line 6. Perl read line 5 as an unfinished statement, continued into line 6, and only there found something that could not be reconciled.

When a Perl syntax error names a line, suspect the line above it first.

What this series covers

This is the first article in a series reading PHP against the language it came from. The premise is simple: a fair amount of PHP that looks arbitrary stops looking arbitrary once you have seen the Perl behind it.

Some of what is coming:

  • Why PHP concatenates strings with . instead of +
  • Why PHP has one array type where Perl has two, and what that cost
  • die(), require, heredocs, and other things PHP took with the names attached
  • What PHP left behind — context, $_, references — and what that simplification bought
  • The lineage from CPAN through PEAR to Composer

Next time: Perl's basic syntax, pragmas, and scalar variables. What use actually is, what a $ variable can hold, and the answer to the . versus + question.


Sources

← Back to the series index

Need this kind of depth on your own stack?

I work on Zabbix monitoring, Linux server configuration, and PHP development. Small, well-scoped tasks are welcome.