I have to caution you that all those detaint regexes also remove a trailing \n (and outright fail if there's a \n anywhere but at the end). Use the //s flag, and also
train yourself to use \z instead of $ when you mean true end-of-string. (AIUI, both these problems are removed in perl6; . and $ can be used more naturally there.)