sub bar { my ($text, $to) = @_; $text =~ s{(\d+)}{qq{qq{$to}}}ee; $text; } print bar("456", 'capture 1 is $1'); # prints capture 1 is 456