Howto: Write script in Perl

Q. I’m new to Linux and Perl. I’ve printed perl man page but it is bit confusing and omits a lot of simple things or details. Can you tell me how do I write a perl script? How do I open perl editor?


A. Larry Wall began work on Perl in 1987 and it is a dynamic programming language. Traditionally perl programs are written using text editor such as vi or emacs. The overall structure of Perl derives broadly from C.

Also when you start learning a new programming language, always start with Hello world program.

Hello world Perl Program

Let us print Hello world from a shell prompt. Type the following command (excluding $ ):
$ perl -e 'print "Hello, world!\n"';

Hello, world!

Let us write hello world program using vi text editor:
$ vi
Append code as follows:
print "Hello, world!\n";

Save and close the file. Now setup a execute permission:
$ chmod +x
Finally execute perl program:
$ ./

  • First, I used the vi command to create a file named
  • The first line of the script used to specify that the script is to be executed by perl program (#!/usr/bin/perl) and not by a shell.
  • Print command prints hello world on screen. Please note that the notation \n which stands for newline i.e. print a newline.

Further reading

This is just a simple introduction. You should consider following text books & resources for more information and mastering the perl:

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

4 comments… add one
  • Andy Jul 18, 2007 @ 17:15

    While you answered the question adequately, I think I understand the ‘asker’.

    When I started leaning PHP, all you have to do is go to and it has an online reference regarding all the functions, even about the language syntax and grammar itself.

    I have looked at Perl, read a book, understand most of it’s syntax and quirks, but I have yet to find a site of’s quality to really ‘dig’ into Perl.

  • 🛡️ Vivek Gite (Author and Admin) nixCraft Jul 18, 2007 @ 17:52


    I agree with you. It is hard for a new person to get started with Perl. is one of the best site for all php related information.

  • Andy Jul 18, 2007 @ 20:24

    Chucks, part of the reason of my post, was polling if you knew a perl equivalent of… guess not!

  • 🛡️ Vivek Gite (Author and Admin) nixCraft Jul 19, 2007 @ 10:14

    Noop, there is no such a site exists, AFAIK. You can try (same as reading perldoc on UNIX)


Leave a Reply

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

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.