use v5.14; chomp(my $word = ); #get word from command line #chomp removes newline for search foreach my $name(@array){ #loop through names if($name =~ m/$word/i){ #if the word is contained within say $name; # print out the name with a newline (say) } } #### use v5.14; chomp(my $word = ); foreach my $name(@array){ if($name eq $word){ #if the name equals the word say $name; } }