use strict; use warnings; use feature 'say'; my $str = 'This ia a real number, 123456.56'; say $str; (my $res = $str) =~ s{ (\d+) }{ sprintf("%s", 4*$1) }xe; # $1*4, just to show /e works say $res; say "\$1 = $1"; (my $adj = $1) =~ s/(\d)/3/g; # replace each \d with '3', same reason say $adj; ($res = $str) =~ s{ (\d+) }{ ($adj = $1) =~ s/(\d)/3/g; $adj }xe; # replace '123456' with '333333', proof of concept say $res;