use strict; use warnings; my @scaffolds; { local $/ = undef; open(IN,"t.txt") or die; @scaffolds = split(/(>scaffold\d+)\n/, ); } close IN; my $i; my $s; foreach (@scaffolds) { if (/^>/) { $s = "$_."; # assemble label for this scaffold $i = 1; # and initialize its counter } else { print map { "$s." . $i++ . "\n" # print incremented label . $_ # and the GACT* stuff } split(/(?:N{4,}\n)+/, $_); # for each entry within the scaffold } }