How can I run a Perl script on Mac OS X?


Perl Problem Overview

How do I run a Perl script on OS X?

Perl Solutions

Solution 1 - Perl

You can run your Perl script by invoking the Perl interpreter and giving your file as input:


Solution 2 - Perl

The easiest way to run a perl script is with the option:


However, you may find it more useful to add a shebang line at the top of the perl file.

print "Hello World!\n";

In order to execute this script, you need to add execute permissions to your program. Run:

chmod +x

Now, in order to run your script, you can simply type:


Solution 3 - Perl

A good tutorial on Perl in OSX can be found here:

A generic documentation on executing Perl code is of course perldoc perlrun.

To answer your question directly:

You can run a perl script on any Unix system by either having the code evaluated and executed from command line:

perl -e 'print "Hello World\n"';

Or you can save your Perl script to a file (customarily having .pl extension, say and with the first line being #!/usr/bin/perl) and then you can execute it as any Unix program (after setting proper execute permissions)


You can also execute a script from a file by running perl interpreter as the command and giving the script as a parameter (in this case execute permissions to the script are not needed):

perl /path/to/script/

Solution 4 - Perl

For some reason the whole directory didn't work for me but I just did

perl ~/Desktop/

(you could also use any folder that is in your user-folder after the ~/)


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJeffView Question on Stackoverflow
Solution 1 - PerlcodaddictView Answer on Stackoverflow
Solution 2 - PerlJeff CataniaView Answer on Stackoverflow
Solution 3 - PerlDVKView Answer on Stackoverflow
Solution 4 - Perlcoding_duckView Answer on Stackoverflow