Do you want to do this for all subdomains with a DNS rewcord or just specific ones? If you want this for some specific subdomains, you will have to use separate rules (unless there is a pattern to match them) as Page Rules don’t support Regular Expressions, only basic wildcards.
I’m not sure you can do that without individual rules for each, given that there isn’t really a pattern to match without matching other hostnames as well.
I assumed since you asked for this that you knew how Workers works.
I can only really refer you to the docs here:
You don’t need to install anything, but can enable Workers on your account, paste and modify the code. You may want to get a developer to help with this if you’re unsure.