my %hash = ( a => 'A', b => 'B', ... ); s/(.)/$hash{$1}/eg;