my $start = qr/A{6}/; my $end = qr/B{6}/; while ( ) { if ( m{$start} .. m{$end} ) { next if m{$start}; next if m{$end}; print; } } __DATA__ hello world0 hello world1 hello world2 AAAAAA this is a test of the emergency broadcast system BBBBBB hello world0 hello world1 hello world2 AAAAAA if this had been a real emergency more instructions would have followed BBBBBB hello world0 hello world1 hello world2 __END__ this is a test of the emergency broadcast system if this had been a real emergency more instructions would have followed