use 5.10.1; use utf8; my $simples = qr{\*\*|//}; my $ps= qr/ (?$simples)(?.*?)\k /x; my @results; my $line= q[You can make things **bold** or //italic// or **//both//** or //**both**//.]; say "Original: [$line]"; while ($line =~ /$ps/pgc) { say "pos is " . pos($line); say "PREMATCH: (${^PREMATCH})" unless length(${^PREMATCH}) == 0; say "SIMPLE: ($+{simple}) ($+{body})"; }