in reply to Word matching in string

The conventional solution is
my %subst; @subst{@name} = ( 1 .. @name ); $phylo =~ s/(\w+)/$subst{$1}||$1/eg;

The || will break down if one of your replacement strings is '0'. Fortunately in this case it is not.