use strict;
my $str = 'RNS Polynomial ([Modulus(68719403009), Modulus(68719230977), Modulus(137438822401)]):(67699591241,42814670386,92925202514)x^0 + (42539574637,55054036653,135659663247)x^1 + (52858091297,11618896202,6855552742)x^2 + (45970532823,20845087073,91272562929)x^3 + (11148839321,55275439733,5401722690)x^4 + (31959765643,40620395732,93052536121)x^5 + (57030732406,66026147059,6304524013)x^6 + (27778918692,11276356856,61606736382)x^7
';
my $regex = qr/\(\[(Modulus\(\d+\)(?:\s*,\s*Modulus\(\d+\))*)\]\):(\(\d+(?:,\d+)*\)x\^\d+(?:\s*\+\s*\(\d+(?:,\d+)*\)x\^\d+)*)/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