Dynamics of a polymer in the presence of permeable membranes