The Ulam--Kaplansky problem up to similarity in operator algebras asks whether A⊕A∼B⊕B implies A∼B. We construct block-diagonal compact operators for which this implication fails. For von Neumann algebras with separable predual, we prove that this cancellation property is equivalent to subhomogeneity. Moreover, we obtain a cancellation law for finite ampliations in unital Banach algebras when the commutant of one element is finite dimensional modulo its Jacobson radical.