sub mail_verify { my $addr = shift; # copied code from Mail::Sendmail begins here my $word_rx = '[\x21\x23-\x27\x2A-\x2B\x2D\x2F\w\x3D\x3F]+'; my $user_rx = $word_rx # valid chars .'(?:\.' . $word_rx . ')*' # possibly more words preceded by a dot ; my $dom_rx = '\w[-\w]*(?:\.\w[-\w]*)*'; # less valid chars in domain names my $ip_rx = '\[\d{1,3}(?:\.\d{1,3}){3}\]'; $address_rx = '((' . $user_rx . ')\@(' . $dom_rx . '|' . $ip_rx . '))'; # copied code from Mail::Sendmail ends here # now use the regex: $addr =~ /^$address_rx$/; }