如何在Perl中使用不断增加的数字替换令牌?

rlb*_*ond 3 string perl

我想用一个数字替换文本文件中的标记.令牌是" <count>",我希望它被替换为目前为止的计数.例如:

This <count> is a <count> count.
The <count> count increases <count><count><count>.
<count><count><count><count><count><count>
Run Code Online (Sandbox Code Playgroud)

变为:

This 1 is a 2 count.
The 3 count increases 456.
789101112
Run Code Online (Sandbox Code Playgroud)

我不是很确定如何做到这一点,也许有一些循环?

my $text = (the input from file, already taken care of in my script);
my $count = 1;
while( regex not found? )
{
    $text =~ s/<count>/($count);
    $count ++;
}
Run Code Online (Sandbox Code Playgroud)

Jim*_*uls 15

my $text = "whatever";
my $count = 1;
$text =~ s/<count>/$count++/ge;
Run Code Online (Sandbox Code Playgroud)

应该为你做.替换结束时的/ e会产生重大影响.