my @to; for my $em ( @$records ) { push @to, @$em; } #### # Slice makes it return an arrayref of hashrefs my $records = $query->fetchall_arrayref({}); my $transport= ... for my $record (@$records) { mail($from, $record->{to}, $subject, $record->{name}); } sub mail { my ($from, $to, $subject, $name)= @_; my $html= .... # form-fill the name into an html template my $email= ... sendmail($email, { transport => $transport }); } #### $transport= Email::Sender::Transport::SMTP::Persistent->new( host => $host, ssl => ($port == 465)? 1 : ($port == 587)? 'starttls' : 0, port => $port, $user? (sasl_username => $user) : (), $pass? (sasl_password => $pass) : (), debug => $log->is_trace, ); #### # Assuming you start with an HTML document for your email: $text= HTML::FormatText::WithLinks->new(unique_links => 1) ->parse($html); #### # Because most mail clients don't properly process