I have till now set a rule that apart from www.example.com if someone types abc/def/anything.example.com the user will get to see the contents of www.example.com This is bcuz of some old sub domains that I couldn't shut off and there were around 2k odd pages that were indexed by google.
Now that those old subdomains can be removed, shall I set a 301 permanent redirection rule for each of those subdomains so that the bots can update accordingly? For instance anything.example.com/test.html will get redirected to www.example.com/test.html
a 301 to your canonical domain would be an improvement compared to serving all that content to multiple subdomains. it would be better if you didn't 301 to a 404 page - i.e. redirect to a non-existent url on www.example.com. you also have to decide what to do about wildcard subdomains. by this i mean subdomains that don't exist and never existed.