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