undef $/;# read in whole file, not just one line or paragraph while ( ) { while ( /AAAAAA(.*?)BBBBBB/sgm ) { print "$1\n"; } } __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 #### this is a test of the emergency broadcast system if this had been a real emergency more instructions would have followed