Why do you always stop quoting that portion of Scripture at verse 19? To understand the CONTEXT of what Jesus is teaching here you need to continue to verse 22.
Matthew 19:16 And, behold, one came and said unto him, Good Master, what good thing shall I do, that I may have eternal life?
Matthew 19:17 And he said unto him, Why callest thou me good? there is none good but one, that is, God: but if thou wilt enter into life, keep the commandments.
Matthew 19:18 He saith unto him, Which? Jesus said, Thou shalt do no murder, Thou shalt not commit adultery, Thou shalt not steal, Thou shalt not bear false witness,
Matthew 19:19 Honour thy father and thy mother: and, Thou shalt love thy neighbour as thyself.
Matthew 19:20 The young man saith unto him, All these things have I kept from my youth up: what lack I yet?
Matthew 19:21 Jesus said unto him, If thou wilt be perfect, go and sell that thou hast, and give to the poor, and thou shalt have treasure in heaven: and come and follow me.
Matthew 19:22 But when the young man heard that saying, he went away sorrowful: for he had great possessions.
The Lord Jesus Christ used the Law to prepare peoples hearts for salvation:
Galatians 3:24 Wherefore the law was our schoolmaster to bring us unto Christ, that we might be justified by faith.
He exposed the sinfulness of mans heart by explaining the deeper meaning of the law, that sin is a matter of the heart and not merely of external actions.
Matthew 5:21 Ye have heard that it was said by them of old time, Thou shalt not kill; and whosoever shall kill shall be in danger of the judgment:
Matthew 5:22 But I say unto you, That whosoever is angry with his brother without a cause shall be in danger of the judgment: and whosoever shall say to his brother, Raca, shall be in danger of the council: but whosoever shall say, Thou fool, shall be in danger of hell fire.
Matthew 5:31 It hath been said, Whosoever shall put away his wife, let him give her a writing of divorcement:
Matthew 5:32 But I say unto you, That whosoever shall put away his wife, saving for the cause of fornication, causeth her to commit adultery: and whosoever shall marry her that is divorced committeth adultery.
In Matthew 19:21, the Lord exposed the sinfulness of the heart of the rich young ruler by getting at the root of sin, which is self. The rich young ruler mistakenly thought that he had kept the law from his youth up (verse 20).
Matthew 19:20 The young man saith unto him, All these things have I kept from my youth up: what lack I yet?
Matthew 19:21 Jesus said unto him, If thou wilt be perfect, go and sell that thou hast, and give to the poor, and thou shalt have treasure in heaven: and come and follow me.
The Lord exposed his sin of covetousness and idolatry by requiring that he give up his wealth and comfort and security and follow Him. This was not to say that the rich young ruler could have been saved by doing this. The only work we can do for salvation is the work of believing on Jesus Christ,
John 6:29 Jesus answered and said unto them, This is the work of God, that ye believe on him whom he hath sent.
but no man can be saved until he first admits his sinfulness and his need for the Savior.
Luke 19:10 For the Son of man is come to seek and to save that which was lost.