Hello World in Perl

Our first program will print the classic “hello world” message. Here’s the full source code.

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

print "hello world\n";

To run the program, save the code in a file named hello-world.pl and use Perl to execute it.

$ perl hello-world.pl
hello world

Sometimes we’ll want to make our Perl script executable without explicitly invoking the Perl interpreter every time. We can do this by adding a shebang line at the top of the file and then changing the file’s permissions to make it executable.

First, ensure the shebang line is present (which it already is in the example), then change the file’s permissions:

$ chmod +x hello-world.pl
$ ./hello-world.pl
hello world

Now that we can run and build basic Perl programs, let’s learn more about the language.