Skip the undef -- variables declared with my are automatically undef or empty as appropriate.
There's no need to predeclare these variables, as there are few scoping changes. Stick a my on the first use and shorten the code several lines. This goes particularly well for loop control variables.
There's also no need to quote numbers, or variables if you're passing them to functions. It's a good habit to break, as eventually you'll start passing around things you don't want to stringify.
You can concatenate in place with $body .= $textarea;. It looks more correct algebraically, too.
Use splice to get at the first 3 elements of @textdata. Or use a list slice to copy them. my @loop = @textdata[0 .. 3];
Use just one regex to find subject lines, capture the first word before the colon, and use that in your if-else.
Personal style, use leading comment blocks. Try to keep your lines shorter than 80 characters for us old dinosaurs who still program from the command line. :)