I believe you are referring to Matthew 5:48
48Be ye therefore perfect, even as your Father which is in heaven is perfect.
While perfect is a good translation for the word "perfect", it actually literally means complete, mature. If you like to read the Strong's concordance (if you don't I highly recommend it) then you can look it up as
G5046 teleios. For your convenience, I linked to Bible Hub's Strong's Greek Concordance.
We can examine how perfect is used in different ways and contexts.
Some examples:
They translated the same word used for perfect in Matt 5:48 to be "men" in 1 Cor. 14:20. The goal being to convey the idea of spiritual maturity, not literal sinless perfection.
1 Corinthians 14:20
20Brethren, be not children in understanding: howbeit in malice be ye children, but in understanding be
men.
Here's another example:
Hebrews 5:14
14But strong meat belongeth to them that are of
full age,
even those who by reason of use have their senses exercised to discern both good and evil.
And there are numerous other examples. We can test that those who are allegedly "men" and of "full age" are not actually perfect in the sense that they are flawless because people keep sinning. It's safe to interpret what Jesus said in Matt. 5:48 as complete, spiritually mature. The complete and spiritually mature person confesses his sins to God when they sin.
Here's an example of how spiritually mature people are not actually perfect, evidenced by the fact their spiritual progression can retrograde.
Hebrews 5:12
12For when for the time ye ought to be teachers, ye have need that one teach you again which
be the first principles of the oracles of God; and are become such as have need of milk, and not of strong meat.