http://www.perlmonks.org?node_id=7472


in reply to How do I write a regex which allows meta-quoting?

Quite nearly there. All that is left is that things in brackets like array subscripts are made into links to other nodes. That ought to be fixable by replacing them with the html codes, which I don't know off the top of my head. Ahh, they are [ -> [ and ] -> ]

To the monks who maintain this monestary I might suggest that they have the node linking ignore []'s inside <pre>'s.
s/(^[(?:([^\\|\A)\\(\\{2})*\#)]*)(.*)/$1/

(?<!)

$c = "\#";
$m = "\\";

while(<IN>) {
  chomp;
  split /\Q$c\E/;
  $_ = $_[0];
  next if(/\A\s*\Z/);
  $string = $_;
  for($i = 1; $i <= $#_; $i++) {
   $_ = $_[$i - 1];
   m/(.)((\Q$m\E){2})*\Z/;
   if("$1" eq "$m") {
     $string .= "$c" . $_[$i];
   } else {
     last;
   }
  }
}