use strict; while (<>) { if (/^>lmo0025/ .. /^>lmo0027/) { last if /^>lmo0027/; print; } } #### use strict; my ($firstfoundflag, $lastfoundflag); while (<>) { if ($firstfoundflag || /^>lmo0025/) { $firstfoundflag++; if ($lastfoundflag || /^>lmo0026/ ) { $lastfoundflag++; if (/^>lmo(?!0026)/) { last; } } print; } }