my %fruitcolors = ( banana=>"yellow" ); $_ = "applebananachocolate"; s/apple(banana)chocolate/$fruitcolors{$1}/ie;