sub boldify { local $/ = undef; my $input = shift; my @parts = split /``/, $input; foreach my $i (0..scalar(@parts)) { $parts[$i] =~ s/\*\*(.+?)\*\*/$1<\\b>/gs if ($i % 2 == 0); } return join '', @parts; } #### my $test_data = <## This is bold<\b>, but this is **not** bold This is **not** bold, but this is bold<\b>, and this is **not** bold This sure is bold<\b> and so is this<\b>, but **this** aint