sub foo { my ($text, $to) = @_; $text =~ s{(\d+)}{$to}; $text; } print foo("123", 'capture 1 is $1');