use strict; use warnings; use Test::More; my $in = 'A |simple*example| is |so*simple| to come*up |with these*days| according to some *experts*'; my $exp = 'A |simple-example| is |so-simple| to come*up |with these-days| according to some *experts*'; my $start = qr/\|/; my $stop = qr/\|/; my $got; for ( split /($start|$stop)/s, $in) { if ( /$start/.../$stop/ ) { #print "<$_>"; s/\*/-/gs; } $got .= $_; } is($got,$exp); done_testing;