in reply to Dynamically generating the replacement part of a substitution

If you're doing this in ways where a given input token needs to broken up into one (or more) output tokens, why not do simple matching or splitting? i.e.
my @captures = ($input_token =~ /$regex/);
Since you know the bits you want to replace already, it'd become something akin to:
my $repl_index = 1; { print "attempt 1 "; my $str = "http://www.domain.com/"; my $regex = qr|http://(.*)\.(.*)\.(.*)|; my @captures = ($str =~ /$regex/i); print "yields: ", $captures[$repl_index], "\n"; }