#!/usr/bin/perl use strict; use warnings; use feature 'say'; my $file = 'file1.txt'; open (my $in, "<", $file) or die "Can't open $file: $!"; while (<$in>) { # assigns each line in turn to $_ chomp; next if /^\s*$/; # skip blank lines say "Line number: " . $. . " Content of line: " . $_; # print contents of $_ line by line } close $in or warn "Can't close $file: $!"; __END__ $ perl test.pl Line number: 1 Content of line: ABS0056 Line number: 3 Content of line: ABS0057 Line number: 5 Content of line: ABS0058 Line number: 7 Content of line: ABS0059