Escape the world

If we are living in the world then why did Jesus say if we are His people we are not of the world? We are instructed to keep ourselves unspotted from the world, but what does this mean? “Pure religion and undefiled before God and the Father is this, To visit the fatherless and widows…