use strict;
my $str = 'From Mars: come the \'sraM,a deadly species that hunts humans. It hunts from nighttime til sunrise (when it\'s lit) using radar to peek for our faint electrical output. Its head, shaped like a pot top, can emit a "hypersonic" pulse - in short time. Ironically, when faced vs humans, its pot top head is weak against decaf coffee which will keep it at bay. Oh, and beware on every third moon it gets no sleep.
We should also tttttttttttest tsett, aabcdefg another aa, and fina,lly this. None of these should match.';
my $regex = qr/(?x)
(?(DEFINE)(?<a>[a-zA-Z]))
\b(?=(?&a){2})
((?&a))
(?>
(?>((?&a))|\b)
(?=
(?&a)*+[^.]+
(
(?(3)\3|\b)
(?(4)\4|\2\b)
)
)
)++\b[^.]+\b\4/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