Looks to me like you're pretty close to getting it. You can finish by moving that block of "logic" (programmers usually call it code) up above the call to MIME::Lite->new(). Now where you want the output from this block to go, put a variable like $data_table. Then all you need to do is figure out how to accumulate rows into $data_table and you're done. Give it a try and post again if you run into problems.
Once you have it working, you might consider taking the next step and putting all that gnarly HTML into a template, perhaps using HTML::Template. Then you can separate the Perl code in your program from the HTML presentation in the email and when the graphic designer complains that you didn't get the font spacing just right you can tell them to fix it themselves!