On a characterization of perfect rings