use strict;
my $str = '
SCHEDULE MASTERAGENTS#KA0HM00_LEASE
DESCRIPTION "Added by composer."
:
CLA0HDST01#/KA0H/KA0HM00_LEASE/KA0HM010_LEASE_AFT
FOLLOWS KA0HM003_LEASE
FOLLOWS KA0HM007_LEASE
CLA0HDST01#/KA0H/KA0HM00_LEASE/KA0HM006_LEASE
FOLLOWS KA0HM004_LEASA
NOP
MASTERAGENTS#/KA0H/KA0HM00_LEASE/KA0HM00SLEASE
CLA0HDST01#/KA0H/KA0HM00_LEASE/KA0HM003_LEASE
CLA0HDST01#/KA0H/KA0HM00_LEASE/KA0HM002_LEASE
FOLLOWS KA0HM001_LEASE
CLA0HDST01#/KA0H/KA0HM00_LEASE/KA0HM001_LEASE
FOLLOWS KA0HM00S_LEASE
MASTERAGENTS#/KA0H/KA0HM00_LEASE/KA0HM00E_LEASE
FOLLOWS KA0HM010_LEASE_AFT
CLA0HDST01#/KA0H/KA0HM00_LEASE/KA0HM004_LEASE
FOLLOWS KA0HM002_LEASE
CLA0HDST01#/KA0H/KA0HM00_LEASE/KA0HM009_LEASE
FOLLOWS KA0HM004_LEASE
END
';
my $regex = qr/(?s)^SCHEDULE(?:.(?!^END$))*?#\/[^\r\n]*E\r?\n(?:(?!^$).)*?[ \t]*NOP$.*?^END$/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html