How to Work with Perl on macOS / Mac OS X
The macOS / Mac OS X operating system comes pre-installed with the libraries needed to run Perl programs. You can
interact with Perl programs via the Terminal application (Applications -> Utilities -> Terminal). To determine
the version of Perl installed, type the following in the Terminal window and then hit enter/return:
This will display the version of Perl pre-installed on the operating system. For example, this may display 5.6.
Perl programs can be created using any text editor such as EditRocket. Perl programs and scripts typically end with the .pl extension. EditRocket will automatically recognize files with the .pl extension as Perl programs, and will color the syntax accordingly.
To create a Perl program, simply create a new file, such as hello.pl. In the file, place the following:
#!/usr/bin/perl print "Hello World!\n";
Notice the first line of the file. Perl scripts should start with the path to Perl on the first line. The path to Perl on Mac is /usr/bin/perl.
The above script can be executed using the EditRocket Tools -> Perl -> Execute Program option,
or you can execute it from the Terminal window. To execute the script in the Terminal, use
the cd command to cd to the directory where the hello.pl file was saved, such as
The type the following:
Hello World! should then be printed to the screen.