I guess that this would also be a solution.
in reply to Array Element Substitution
Adapt to your application..
my $heredoc = <<END;
This is a whole bunch of stuff with Jupiter
and Mars and Earth and Venus and Saturn.
Also could be Earth and Earth and something else like Neptune.
my $xlatedoc = <<END;
open (XLATE, '<', \$xlatedoc) or die "xlatedoc failed: $!\n";
my ($planet, $host) = split; #no chomp() needed
my @planets = keys %xlate;
my $all_planets = join ('|',@planets);
open (IN, '<', \$heredoc) or die "heredoc failed: $!\n";
# $all_planets is an OR expression
# $1 winds up being which one of the OR'ed terms matched
# that gets translated to the new term
This is a whole bunch of stuff with host1
and host2 and host3 and Venus and Saturn.
Also could be host3 and host3 and something else like Neptune.