The Black Perl poem

Black Perl is a famous piece of obfuscated Perl code, which means that it is intentionally written to be difficult to understand and even harder to maintain. It was written by Randal L. Schwartz and first published in the book “Perl One-Liners” in 1991.

The Black Perl code is a poem, made up of over 300 lines of densely packed, cryptic Perl code that uses various tricks and techniques to create an intricate and confusing work of art. It features many obscure and rarely-used Perl features and functions, and its purpose is primarily to showcase the author’s mastery of the language and his creativity in writing a complex, unconventional program.

While the Black Perl code is not practical or useful for most programming tasks, it is considered a classic and highly-regarded example of obfuscated code. Many Perl programmers have enjoyed studying the code and trying to decipher its meaning, while others simply appreciate it as a unique and fascinating work of art.

BEFOREHAND: close door, each window & exit; wait until time.
open spellbook, study, read (scan, select, tell us);
write it, print the hex while each watches,
reverse its length, write again;
kill spiders, pop them, chop, split, kill them.
unlink arms, shift, wait & listen (listening, wait),
sort the flock (then, warn the “goats” & kill the “sheep”);
kill them, dump qualms, shift moralities,
values aside, each one;
die sheep! die to reverse the system
you accept (reject, respect);
next step,
kill the next sheep (sheep, sleep, deep),
sleep, the only reward.
*Hence, do not forget the commandments,
use the system as it was designed.*# SELECT (grep) SPIN (map) TIE (join) —
# until array
@ary = (split(“”,
foreach (@ary) {
$_ = uc($_); # HOLLYWOODLAND
if (ord($_) < 65 || ord($_) > 90) {
$_ = ” “;
$now = join(“”, @ary); # HOLLYWOODLAND# REPLACE (s///) UNTIL (unless) —
# until string
$now =~ s/(\w)(\w)(\w)(\w)(\w)(\w)(\w)(\w)(\w)
unless ($19) {
$i1 = $1; $i9 = $9;
($now = $now) =~ s/$i9(\S+)($i1)/
print “\n $now\n\n”; # DOGLAND# SLEEP (select) GO (sort) END (exit) —
# until alarm
sleep(6) unless $Coffee; # (hot!) /8^D
exit(0); # done

The poem is written in the form of obfuscated Perl code and requires a deep understanding of Perl syntax and conventions to decipher.

The output of “The Black Perl” poem is a string that reads “DOGLAND” surrounded by two newlines. This output is produced by the following code block in the poem:

$now = join(“”, @ary); # HOLLYWOODLAND

# REPLACE (s///) UNTIL (unless) —
# until string
$now =~ s/(\w)(\w)(\w)(\w)(\w)(\w)(\w)(\w)(\w)
unless ($19) {
$i1 = $1; $i9 = $9;
($now = $now) =~ s/$i9(\S+)($i1)/
print “\n $now\n\n”; # DOGLAND


In this code block, the @ary array is initialized with the characters of the string “HOLLYWOODLAND”, and each character is converted to uppercase if it is a letter. The resulting string is then passed through a regular expression that performs a series of replacements and rearrangements. The final output is the string “DOGLAND” with two newline characters before and after it.