Try this:
perl -wlne'print $1 if /key\s*=\s*\"?([^\"; ]+)[\" ;]/' source.cpp
It pulls out everything after key =
and before a closing quote/space/semicolon. if you've got strings with escaped quotes, this will fail, so this should only be used if you need a quick and dirty solution. If you are parsing production data, log files etc, you should use a module in the Parse::
family on CPAN, rather than using regular expressions.
I've to re-use these values in another unix command.
Perhaps you should be defining these values in a central location (like a constants file, or a config file), rather than attempting to parse source code.. it would be far less error-prone (not to mention hacky).