my $str = 'I have a green shirt and a blue hat'; my ($YELLOW, $RED) = qw(yellow red); # I wish that could have worked somehow $str = tr/green,blue/$yellow,$RED/; # requested result print $str; # would print: I have a yellow shirt and a red hat