use strict; use warnings; use feature 'say'; my $txt = q{ Uninteresting line. More boring stuff. Here's the AATCCGCTAG string. Afterwards, more drivel. Footnotes, etc. }; my @lines = split "\n", $txt; my $counter = 0; for my $line ( @lines ) { $counter++; next unless $line =~ /(\b[ACGT]+\b)/; say "Found $1 in line $counter"; } __END__