When using modern fonts in conjunction with LuaLaTeX or XeLaTeX, one is (sometimes) able to delegate this this to the font, since OpenType Layout defines a font feature c2sc that translates capital letters to small cap letters. Unfortunately, Latin Modern does not contain this feature. When available, one can activate this via fontspec feature Letters=...
Here's a LuaLaTeX-based solution. It consists of (a) a main Lua function called uc2sc (short for "uppercase to smallcaps", I suppose) and an auxiliary Lua function called makesc which, together, do most of the work and (b) a LaTeX macro called \famword that acts as a wrapper for the uc2sc function. The Lua functions employ Lua's versatile built-in string....
The tokcycle package (https://www.ctan.org/pkg/tokcycle) can be used for this.