You're not using open in a sane way, consider copying the examples from the documentation, checking and reporting on errors (the $! variable). You don't print every email address matching your criteria to a file, if it exists more than once you're going to have duplicates. To find only the unique email addresses you can use the List::MoreUtils module, or roll your own. A good discussion of this problem and in depth description of an alternate solution can be found in Unique values in an array in Perl.