undef $/;# read in whole file, not just one line or paragraph while ( <> ) { while ( /AAAAAA(.*?)BBBBBB/sgm ) { print "$1\n"; } }