perlrun Fun! Remote Script Execution with -x

By | Perl

Last night I was perusing Perl’s online documentation site ( I really enjoyed the experience, it is well written and a treat to read! While checking out perlrun I found a tidbit that caught my attention.

  • -x tells Perl that the program is embedded in a larger chunk of unrelated text, such as in a mail message. Leading garbage will be discarded until the first line that starts with #! and contains the string “perl”. Any meaningful switches on that line will be applied. The program must be terminated with __END__ if there is trailing garbage to be ignored; the program can process any or all of the trailing garbage via the __DATA__ filehandle if desired.

This gave me an idea! I can launch my code straight from this website with this command line parameter. After testing it I am happy to report it works! One caveat I noticed was with the strict pragma on you can’t add the ampersand sigil to functions.

Here are 2 ways I found to execute code from a remote source with the -x parameter.

NOTE: Careful if you execute the command line below as printed. It will recursively rename all the files in the folder you are in. (I am just using it as an example).


This uses the bash construct <() which sets the output of a command to a temporary process (process substitution). This will create a temporary path which can be opened like a file.

perl -x <(curl -sSL '')


This version pipes the HTML output to perl.

curl -sSL | perl -x

Leave a Reply

Your email address will not be published. Required fields are marked *