ANSWER: Interestingly, although somewhat rare and usually sought after, the KJV bible mentions pearls in only eight places. Four of these locations are in the book of Revelation. The verse you are referring to is in Matthew 7. This verse records Jesus stating we are not to offer holy things to dogs and we are not to cast our pearls before swine. Why not do this? Because they might walk over them and then afterwards come and attack us!
Jesus stated, "Do not give that which is holy to the dogs, nor cast your pearls before the swine, lest they trample them under their feet, and turn around and tear you in pieces" (Matthew 7:6, HBFV).
The word "pearls" in Matthew 7 is symbolic of godly wisdom and the salvation brought by his kingdom. God's wisdom is likened to something of a very great price in another reference in Matthew (see Matthew 13:45 - 46). All this is discussing God's kingdom and the wisdom one must acquire in order to enter it (Job 28:12 - 20).
Wisdom is found using the Holy Spirit, which is only given to those who obey him (Acts 5:32). However, how can understanding and knowledge lead us to our own pearls of great price (Matthew 13:45 - 46)? How can they bring us to the pure truth of God? It is only through recognizing and obeying his laws and his ways (Psalm 119:104).
God's precepts are written in the Holy Scriptures. If one has his Spirit, one can study his Word (His Precepts) for Holy knowledge, and upon this foundation of the Holy Spirit and Holy knowledge, the Eternal will then grant Holy understanding.
If we take our wisdom (like precious pearls) and throw it all around without knowing whether it might fall before dogs (an impure or self-righteous heart) or swine (someone who is considered unclean), Jesus warns us that they will likely tear us to pieces. This means they will twist and distort what is said and then come after us!
God tells us in the book of Proverbs that there are times when we should be silent (not casting our pearls before others) and times when we should respond directly (especially about what is the truth). Jesus sometimes answered the questions and accusations thrown his way by the religious leaders of his day (e.g. Matthew 12:1 - 8) and sometimes refused to respond to their inquiries (e.g. Matthew 21:23 - 27).
We must discern the reason for any questions according to the person who is doing the asking and answer within that context (Proverbs 26:4 - 5). We should not cast our pearls of Godly wisdom before 'swine', meaning someone who is a militant, ready to fight, unbeliever lest they turn on us and insult us or do us harm.