#!/usr/bin/perl $/ = undef; $_ = ; while ( /begin(.*?)end/g ) { print "\n--- found without 's': ---\n$1\n"; } while ( /begin(.*?)end/gs ) { print "\n--- found using 's': ---\n$1\n"; } __DATA__ blah begin foo bar baz end begin foo2 bar2 baz2 end