$text =~ s/ (?<= \[ ) ([^\]]*) (?= \] ) / strip_slash($1) /gex; sub strip_slash { $_=pop; s/\\//g; $_; }