I am looking for a command in sed which transforms this input stream:
sed
dummy (key1) (key2)dummy(key3) dummy(key4)dummy dummy(key5)dummy))))dummy
In Perl, you can use Marpa, a general BNF parser — the parser code is in this gist.
BNF parser is arguably more maintainable than a regex. Parens around grammar symbols hide their values from the parse tree thus simplifying the post-processing.
Hope this helps.