Sure you can... you just have to not extend those benefits in full to new migrants. Europe seems slowly moving in that direction in response to this exact problem, though it's not straightforward as the current jurisprudence seems to regard this as an infringement on EU citizens' freedom of movement.