0] # cat test_range while( $text= ){ print "$. $text"; if ( ($text=~/^AAAAAA/) .. ($text=~/^BBBBBB/ ) ){ if ($text=~/^AAAAA/){ print "========= Start of the fragment detected at $.\n"; } print "Still true at $.\n"; $end=$.; # Is this the only way to detect the end of the fragment? } } print "========= End of the fragment detected at $end.\n"; __DATA__ aaa aaa AAAAAA ccc ddd BBBBBB 111 222 333 CCCCCC 444 555 666 DDDDDD 777 888 999