]; foreach( @records ) { my $message = $template; # hash to fill with customer information my %customer_record; # use a hash slice to populate it, # we now have keys fname lname email and phone @customer_record{ @field_names } = split ';', $_ ; # neat, a one line templating engine. $message =~ s/##$_##/$customer_record{$_}/g for keys %customer_record; send_spam $customer_record{email}, $message; }