I don't know how to do it with a one-liner.
The "add only if not already present" requirement is much more easily done by building a hash instead of an array.
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
my %emails = ('sam@email.com' => undef,
'john@email.com' => undef,
'jenifer@email.com' => undef);#Hash of emails
while (<DATA>){
chomp;
s/^Zip_Name: //;#Remove unwanted text at beginning of $_ (default record variable)
$emails{$_} = undef; #Email as key in hash automatically unique.
}
say "Hash contains the following emails:";
say foreach (sort keys %emails);
__DATA__
Zip_Name: jenni@email.com
Zip_Name: sam@email.com
Zip_Name: dave@email.com
Zip_Name: john@email.com
This gives the following output:
Hash contains the following emails:
dave@email.com
jenifer@email.com
jenni@email.com
john@email.com
sam@email.com d5e5
Practically a Posting Shark
810 posts since Sep 2009
Reputation Points: 159
Solved Threads: 159