Categories: Ubuntu

How to create and run a Perl script in Ubuntu 22.04 LTS

Perl is a simple and easy-to-learn programming language for beginners. Although Perl is an old-age computing language; however, it can still be used to develop large and complex programs as any structured programming language can do.

The Syntax of Perl is like that of the C programming language. The Per community has contributed more than 250000 software modules that are available on the CPAN (Comprehensive Perl Archive Network). Due to its large community and support, Perl scripts are widely used in Bioinformatics, Multi-tasking, Networking, GUI development, and so on. We have compiled this post to guide you how a Per script can be created and run on Ubuntu 22.04.

Prerequisites
Sponsored

The Perl script can be executed subject to the presence of Perl on Ubuntu 22.04. If you have not installed Perl on Ubuntu 22.04 then you must get the latest version of Perl from the Ubuntu’s official repository by using the following command:

$ sudo apt install perl

How to create and run a Perl script on Ubuntu 22.04

The Perl script can be created and run by using the command line application of Ubuntu 22.04. We have compiled a step-by-step procedure to create and run a Perl script on Ubuntu 22.04.

Step 1: Fire up the Ubuntu terminal (CTRL+ALT+T) and create a “.pl” file as follows:

$ touch test.pl

Step 2: You need to edit the newly created “.pl” file by using any text editor (nano or vim). We have used the nano editor to edit the “test.pl” file via the following command:

$ sudo nano test.pl

Once the file is opened in an editor, write the following line to tell your Ubuntu 22.04 to execute this file (test.pl) using the Perl interpreter:

#!/usr/bin/perl

After that, we added a simple print statement in “test.pl“:

$message=“Hello, Welcome to LinuxHint”;

print($message n);

Sponsored

Once all is done, press “CTRL+S” and “CTRL+X” to save the changes and come out of the editor respectively.

Step 3: Try to run the Perl script “./test.pl” via the following command:

$ ./test.pl

If any execution error occurs (as shown in the above output), you need to provide the execution privileges to the Perl script as follows as we did here with “test.pl“:

$ chmod +x test.pl

Use the following command again to execute the test.pl script.

$ ./test.pl

Here you go!

Conclusion

A Perl script can be created by using any text editor on Ubuntu 22.04. You can run the Perl script from the terminal of Ubuntu 22.04. Perl is an open-source interpreted programming language that is well known in Linux-based operating systems because of its networking and multitasking support. Here, you have learned to create a Perl script and run it on Ubuntu 22.04.

Ubuntu Server Admin

Recent Posts

AI in 2025: is it an agentic year?

2024 was the GenAI year. With new and more performant LLMs and a higher number…

43 minutes ago

Canonical announces 12 year Kubernetes LTS

Canonical’s Kubernetes LTS (Long Term Support) will support FedRAMP compliance and receive at least 12…

1 day ago

Ubuntu Weekly Newsletter Issue 878

Welcome to the Ubuntu Weekly Newsletter, Issue 878 for the week of February 2 –…

2 days ago

How your feedback shapes the way we support open source software

At Canonical, we firmly believe that delivering an outstanding, customer-centric support experience is impossible without…

2 days ago

How To Install osTicket v1.14 On Ubuntu 20.04

I want to share how to install osTicket v1.14 for Ubuntu 20.04 server. osTicket written…

3 days ago

How To Install WordPress On Ubuntu 20.04

Now I want to share how to install WordPress on ubuntu 20.04 server. WordPress is…

3 days ago