sub match { my (@newemails, @emails); # Email addresses to ignore my $ignore = qr(([-.\w]+\@apnic\.[com|net]) | ([-.\w]+\@uu\.net) | (hostmaster\@nic\.or\.kr) | ([-.\w]+\@[RIPE\.NET|ripe\.net]) | ([-.\w]+\@iana\.org) | (NOC\@SPRINT\.NET); # Save all emails from whois query to an array @emails = $result =~ m/([-.\w]+\@[-.\w]+)/g; my %saw; @emails = grep(!$saw{$_}++, @emails); #remove duplicates # Remove all ignore emails and save to new array foreach (@emails){ next if $_ =~ $ignore; push(@newemails, $_); } #Save the email and domain portion to separate vars my ($email, $domain) = split(/\@/, $newemails[0]); #Run the mail sub for each email address &mail($newemails[0], $domain); } *Note: I know my regex will not match 100% of emails, but I'm happy with 75 - 90%. It's been working out well so far.