Q:

How do I substitute two same words (of different cases) to another two words whilst retaining their original cases?

I am sorry that my English was not good enough to clearly describe the task in the title.
Here is a more descriptive attempt. Let us say I have the following text
\gls{tla}{TLA}

(As a side note, this is a partial excerpt from a latex document. This command is useful for defining acronyms and generating glossary later on.)
The question is the following: Let us say, I have copied  the line immediately below with yyp.
\gls{tla}{TLA}
\gls{tla}{TLA}

I wish to change the second line to the following with a single edit operation.
\gls{tla}{TLA}
\gls{tbd}{TBD}

i.e. I wish to perform a substitution for the case-sensitive and case-insensitive version in one go. I believe this is possible with some knowledgeable vim-fu, since it involves only a single semantic transformation (and the case conversion can be seen as a side-effect/add-on operation that remain fixed in sequence.)
Any ideas on how to achieve this? I am not opposed to the use of plugins to aid this, but standalone & elegant pure vim-only solutions (with some very-magic regex) will also be highly appreciated.

A:

I will assume you are starting with the following, i.e., after changing all the first arguments using any text editing method (e.g., visual block mode).
\gls{tbd}{TLA}
\gls{foo}{TLA}
\gls{bar}{TLA}

Now, all we need to do is make the second argument match.  A simple way to do this is:
:%s/\\gls{\(\w\+\)}{\zs\w*\ze}/\=toupper(submatch(1))

Breaking it down, we look for \gls{word}{..} and capture the word into group \1.  Targeting only the second argument using \zs..\ze, we replace with a transformed version of the word (\= allows us to use an expression for replacement).

