For which functions f does A is an element of G double right arrow f(A). G when G is the matrix automorphism group associated with a bilinear or sesquilinear form? For example, if A is symplectic when is f( A) symplectic? We show that group structure is preserved precisely when f( A(-1)) = f(A)(-1) for bilinear forms and when f(A(-*)) = f(A)(-*) for sesquilinear forms. Meromorphic functions that satisfy each of these conditions are characterized. Related to structure preservation is the condition f((A) over bar) = <(f(A))over bar>, and analytic functions and rational functions satisfying this condition are also characterized. These results enable us to characterize all meromorphic functions that map every G into itself as the ratio of a polynomial and its "reversal," up to a monomial factor and conjugation. The principal square root is an important example of a function that preserves every automorphism group G. By exploiting the matrix sign function, a new family of coupled iterations for the matrix square root is derived. Some of these iterations preserve every G; all of them are shown, via a novel Frechet derivative-based analysis, to be numerically stable. A rewritten form of Newton's method for the square root of A. G is also derived. Unlike the original method, this new form has good numerical stability properties, and we argue that it is the iterative method of choice for computing A(1/2) when A. G. Our tools include a formula for the sign of a certain block 2 x 2 matrix, the generalized polar decomposition along with a wide class of iterations for computing it, and a connection between the generalized polar decomposition of I + A and the square root of A is an element of G.