in reply to s///g within m//g regions

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11138609 use warnings; my $have = <<END; # turn * into - within |...| regions A |simple*example| is |so*simple| to come*up |with these*days| END my $want = $have =~ s{\|[^|]*\|}{ $& =~ tr/*/-/r }ger; print "$have\n$want";

Outputs:

# turn * into - within |...| regions A |simple*example| is |so*simple| to come*up |with these*days| # turn * into - within |...| regions A |simple-example| is |so-simple| to come*up |with these-days|