Let R be a unit-regular ring, and let a, b, c ∈ R satisfy aba = aca. If ac or ba is Drazin invertible, we prove that their Drazin inverses are similar. Furthermore, if ac and ba are group invertible, then ac is similar to ba. For any n × n complex matrices A, B, C with ABA = ACA, we prove that AC and BA are similar if and only if their k-powers have the same rank. These generalize the known Flanders' theorem proved by Hartwig.