#!/usr/bin/perl use strict; use warnings; my @lines = ; for my $line(@lines) { print "| $line |"; if ($line =~ /()/) { # note, no need to capture the whole of row 9 print "$1 \n\n"; } else { print "Crummy regex\n" } } __DATA__ 9 SUBSIDIARIES OF THE REGISTRANT 0009.txt EX-21.1 And here's execution: C:>wrkrbeejunk.pl | 9 |Crummy regex | SUBSIDIARIES OF THE REGISTRANT |Crummy regex | 0009.txt |0009.txt | EX-21.1 |Crummy regex C:\>