Some simple Perl and Regex Reads from a flat file of three columns, delimited by at least one tab character.  Filters the three columns based on input; returns list of corresponding emails.  Arguments passed like key=value or key= for blank.

#!/bin/perl 
use warnings;  
use strict;    

sub get_list {
   my $cols   = {'list'=&gt;0, 'email'=&gt;1, 'sub'=&gt;2};  
   my $list   = '[a-z0-9_\- ]+';
   my $email  = '[a-z0-9@\._\-]+';
   my $subls  = '[a-z0-9\. ]+'; 
   my $return = $cols-&gt;{'email'}; 
   foreach (@ARGV) {
      my ($key, $value) = split '=';
      $value = q{} if not defined $value;  
      if    ($key eq 'list')   { $list  = $value; }
      elsif ($key eq 'email')  { $email = $value; }
      elsif ($key eq 'sub')    { $subls = $value; }
      elsif ($key eq 'return') { 
         $return = $cols-&gt;{$value} 
                   if defined $cols-&gt;{$value}; 
      }
      else  { die "invalid key: $key\n"; }
   }   
   my $file = 'input.txt';  
   open FH, '&lt;', $file 
         or die "Could not open '$file' $!\n";   
   my %emails = map { (split /\s*\t\s*/)[$return] =&gt; 'tacos' }
                grep m/^${list}\s*\t\s*${email}(\s*\t\s*${subls})?\s*$/gi, 
                &lt;FH&gt;; 
   close FH; 
   return (join ', ', keys %emails);   
} 

print get_list(@ARGV);
print "\n"; 

# test input... three columns delimited by at least one tab
# third column may be blank.  nothing should contain spaces
# in real life, but i'm allowing it... 

# archive   email@email.com success
# archive       email2@email.com    fail
# archive   email2@email.com    success
# archive   email3@email.com    
# archive   email@email.com fail    
# taco  email@email.com success
# taco  email2@email.com    fail
# taco  email2@email.com    success
# taco meat     email3@email.com    
# tacor email@email.com fail    


I realize some people may not be down with the $thing = $value if defined $value; arrangement but I went ahead and used it since the logic wasn't complex.  I prefer it over using space for brackets on one line conditionals.  Also, please note, I'm not trying to validate email addresses with regex and I these are truly the only characters the strings will contain.  



for the future person... this is what I ended up with: 

#!/bin/perl
use warnings;
use strict;

sub get_list {
   my $file = 'input.txt';
   my %emails; 

   my $cols  = {'list'=&gt;0, 'email'=&gt;1, 'sub'=&gt;2, 'subls'=&gt;2};
   my $index = $cols-&gt;{'email'};

   my $dlmtr = qr{\s*\t\s*};
   my $list  = qr{[a-z0-9_\- ]+};
   my $email = qr{[a-z0-9@\._\-]+};
   my $subls = qr{[a-z0-9\. ]+};

   foreach (@ARGV) {
      my ($key, $value) = split qr{=};
      $value //= qr{};
      if    ($key eq 'list')   { $list  = $value; }
      elsif ($key eq 'email')  { $email = $value; }
      elsif ($key eq 'sub')    { $subls = $value; }
      elsif ($key eq 'return' &amp;&amp; defined $cols-&gt;{$value}) {
         $index = $cols-&gt;{$value};
      }
      else  { die "invalid key: $key\n"; }
   }

   open FH, '&lt;', $file or die "Could not open '$file' $!\n"; 
   while (&lt;FH&gt;) {
      chomp;

      # i couldn't get the syntax in the accept answer to parse for me
      # so i changed it to this... also, %emails is better as a hash
      # b/c it prevents emails added multiple times... and for my thing,
      # the first two columns are required but the third may be blank.

      if (m/^${list}${dlmtr}${email}(${dlmtr}(${subls}))?\s*$/gi) { 
         my $value   = (split $dlmtr)[$index]; 
            $value //= q{}; 
         $emails{ $value } = 'tacos';  
      }
   }
   close FH;

   return join ' ', keys %emails;
}
my $cols   = {'list'=&gt;0, 'email'=&gt;1, 'sub'=&gt;2};


I'd call this 

my %index_of = { 'list' =&gt; 0, 'email' =&gt; 1, 'sub' =&gt; 2 };


and later, change $return to 

my $index = $index_of{'email'};


The following is used oddly:  

print get_list(@ARGV);
foreach (@ARGV) {


You are calling the function with parameters @ARGV but you never use the parameters in the function.  Instead, you use @ARGV again.  Better would be to use the function parameters:

my @arguments = @_;
foreach my $argument (@arguments) {
   my ($key, $value) = split {=}, $argument;


I also switched to using a named element instead of letting it default to $_.  

Alternately, you could pass nothing into the function and use @ARGV in the foreach as you did.  That would work but isn't a best practice.  

You may not have realized but the '=' was a regular expression with single quotes as the delimiters.  I prefer to use curly brackets for regular expressions.  If you wanted to be really plain about it, you could have said qr{=}.  

# default patterns that can be overridden by command line arguments
my $list   = qr{[a-z0-9_\- ]+};
my $email  = qr{[a-z0-9@\._\-]+};
my $subls  = qr{[a-z0-9\. ]+};
  $value = qr{} if not defined $value; 


Using qr{} here makes it more obvious that these are regular expression patterns.  

open my $fh, '&lt;', $file 


I'd prefer a variable here rather than a globally scoped bareword.  

my $SEPARATOR = qr{\s*\t\s*}
my %emails = map { (split $SEPARATOR)[$return] =&gt; 'tacos' }
             grep m{^${list}${SEPARATOR}${email}(${SEPARATOR}${subls})?\s*$}gi, 
             &lt;$fh&gt;;


By defining $SEPARATOR, we make the regular expressions clearer and reduce the amount of repeated code.  

my @entries = ();
while ( my $line = &lt;$fh&gt; ) {
   @columns = m{\A(${list})${SEPARATOR}(${email})(${SEPARATOR}(${subls}))?\s*\z}gi;
   if ( scalar @columns &gt;= 2 ) {
      push @entries, $columns[$index];
   }
}
close $fh;

return (join ', ', @entries); 


This is clearer about what it is doing than the map of the grep results.  Also, it doesn't parse each line twice.  And of course it doesn't define a hash just to get the keys.  

In general, I would make more use of paragraphing.  This is extra new lines to separate blocks of code.  This allows you to easily see what pieces of code go together.  For example, note how I separate the return from the file handling code.  

You have comments explaining what the file format should be, but you don't explain what the command line arguments should be.  A user would have to read the code to figure it out.  

Your function does two distinct things.  First, it reads the command line arguments.  Second, it opens a file and processes it based on the command line arguments.  It would be better if you could separate that into two functions.