Would you like to learn how to read a text file using Perl? In this tutorial, we are going to show you how to use Perl to read a line from a text file on a computer running Windows.

• Ubuntu 20
• Ubuntu 19
• Ubuntu 18
• Perl

Equipment list

The following section presents the list of equipment used to create this tutorial.

As an Amazon Associate, I earn from qualifying purchases.

Related tutorial - Perl

On this page, we offer quick access to a list of tutorials related to Perl.

Tutorial Perl - Read a text file

Install Perl.

Copy to Clipboard

Create a text file.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

In our example, we create a text file named NAMES in the TMP directory.

Create a Perl script to read a text file and print it on the screen.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

Run the Perl script.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

Congratulations! You are able to read a text file using Perl.

Tutorial Perl - Read lines from a text file

Install Perl.

Copy to Clipboard

Create a text file.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

In our example, we create a text file named NAMES in the TMP directory.

Create a Perl script to read a text file and print it on the screen.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

Run the Perl script.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

Congratulations! You are able to read a text file using Perl.