You have a couple syntax errors in your code that cause unexpected results.
First, if you need an empty array, you need to write:
my @array = ();
my @array = [];
my @array = undef;
You also need to cancel the grep condition - the regular expression should be on the right side of the statement =~:
perl -e '@arr = (); print "HELLO." unless grep { $_ =~ /asdf/} @arr;'
If you make these two changes, the code will do what you expect.
source
share