Regex search and replace match only

In perl I have a long string but here is the important part $abc = "...Testvalue1 100...";

Is there a way to use Regex to search for the number right after Testvalue# and replace it with a variable?

Here is what I have so far:

my $abc = "...Testvalue1  100...";
for my $i (1..100) {
    $abc =~ s/Testvalued+W+(d+)/$i/;
    print $abc . "n";

Unfortunately this replace the entire match with $i, not just the first match of (d+). Is there a way to do this?

My desired output would be:

Testvalue1  1
Testvalue1  2
Testvalue1  100

Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.