The prophet Daniel was chosen to serve in the palace of a pagan kingdom, and in the time of his preparation for this service, the king would provide a daily portion of meat and wine to Daniel and other chosen men. However the Bible says in Daniel 1:8-12 that Daniel purposed in his heart not to defile himself with the royal food, and made a special request instead to eat only vegetables and water.
Similarly, in our society today we have many things made available to us which can defile us spiritually if we choose to partake in them. For example, opportunities to engage in gossip with coworkers or other useless conversations. There is also a variety of godless entertainment like violent movies or lustful music which defiles us spiritually by watching or listening to it. Like Daniel, we have to say no to these things in order to avoid compromising our walk with the Lord.
One of the things we can observe about Daniel is that he was a prayerful man (Daniel 6:10) and he spent time in the scriptures (Daniel 9:2). Likewise, through prayer and the study of God’s Word, God will also equip us to live godly lives in the midst of an ungodly world.
John 17:15 KJV
I pray not that thou shouldest take them out of the world, but that thou shouldest keep them from the evil.
Romans 12:2 KJV
And be not conformed to this world: but be ye transformed by the renewing of your mind, that ye may prove what is that good, and acceptable, and perfect, will of God.