Defect and strain engineering for modulating structure and magnetism in perovskites