use strict; use warnings; #Just listing a few bad chars (I think hehe) for example my %escap_chars = ( '>' => '>', '<' => '<}; #Text for email would either be in array or scalar I'll presume my $email_text = 'Hi this is a math email 2 + 2 = 4. and 4 > 5'; #if scalar foreach my $key (keys(%escape_chars)) { $email_text =~ s/$key/$escape_chars{$key}/g; } # if each line of email is in an array foreach my $key (keys(%escape_chars)) { s/$key/$escape_chars{$key}/g for(@email_text); }