my $simples = qr{\*\*}; # extensible by user. Same opening and closing. my $ps= qr{(?.*?) (?: (?:(?.*?)\s*(?: (?:(?$simples)\s*(?.*?)\s*(?:\k|\Z)(*:simple) | \\\\ (*:break) | \[\[\s*(?.*?)\s*\]\](*:link) | \Z (*:nada) # must be the last branch ) }xs; my @results; while ($line =~ /$ps/g) { # careful not to trash my capture variables! So no using regex at all until I determined what I need and saved it. my $prematch= $+{prematch}; my $s; my $body= $+{body}; if ($REGMARK eq 'simple') { my $style= $+{simple}; $s= $self->simple_format ($style, $body); } elsif ($REGMARK eq 'italic') { $s= $self->simple_format ('//', $body); } elsif ($REGMARK eq 'break') { $s= $self->format_tag ($self->get_tag_data('br'), undef); } elsif ($REGMARK eq 'link') { $s= $self->process_link_body ($body); } # other cases... push @results, $self->escape($prematch) unless length($prematch)==0; push @results, $s if defined $s; } return join ('', @results); }