sub expand { my ($rx, $from, $to) = @_; if ($from =~ /$rx/) { print (eval $to)."\n"; } } #expand(qr/a(.)c/, 'abc', 'a$1$1c'); expand('a(.)c', 'abc', "a$1$1c");