≡ Menu

Perl Hello World Example: How To Write and Execute Perl Program on Unix OS

Question: I would like to understand the basics of how to write and execute Perl program on Linux OS. Can you explain it with a simple example?

Answer: In this article, let us review very quickly how to write a basic Hello World Perl program and execute *.pl program on Linux or Unix OS.

1. Write a Hello World Perl Program

Create the helloworld.pl program using a Vim editor as shown below.

$ vim helloworld.pl

#!/usr/bin/perl

# Hello world perl program

print "Hello World!";

2. Make sure Perl Interpreter is installed on your system

Make sure perl interpreter is installed on your system as shown below.

$ whereis perl
perl: /usr/bin/perl /etc/perl /usr/lib/perl
/usr/share/perl /usr/share/man/man1/perl.1.gz

$ which perl
/usr/bin/perl

3. Execute the Perl Program

You can either execute using “perl helloworld.pl” or “./helloworld.pl”.

$ perl helloworld.pl
Hello World!

( or )
$ chmod u+x helloworld.pl

$ ./helloworld.pl
Hello World!

Note: As perl is an interpreted language, you don’t have the compilation step similar to the C program.

4. Writing and Executing Perl One liner

You can also execute perl from the command line as shown below. This will print Hello World!.

perl -e 'print "Hello World!\n"'
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • sangita March 5, 2013, 9:56 am

    I am using windows xp operating system. please tell me how I will write code in perl scripting and how I will execute them.

  • dilip May 24, 2013, 5:16 am

    Hi Sir,
    as u posted it is to know how to execute perl program.but i need full perl tutorial.because as a Linux administrator i have to know perl scripting.could you please provide me the best understanding perl tutorial.

    if you help me it would be great.
    Thanks in advance,

    Regards
    Dilip

  • Arunkumar July 10, 2013, 8:36 am

    Hi
    Ramesh
    Am in very critical situation that i have to learn perl,being a zero in programming i have to start learning perl.Please guide me the basic * Should i install linux server to my system * where to type all the script * how to save ,execute *if error comes how can i correct …Please please please give your valuable time to me to guide me …..so that i can start learning perl with confidence.

  • Karan January 12, 2016, 3:53 am

    Hi, Linux already inbuilt Perl python u just need to find details by commands as perl -v – for version n get the command prompt
    perl -V for starting perl
    vim p.perl
    in file
    print “hello Perl ”
    Close file n execute it by
    perl p.perl