in reply to Weird grep behaviour

The following might surprise you:
use strict; use warnings; use Data::Dumper; my @arr1 = ('a'); my $var1 = 'b'; my (@surprise) = grep($var1, @arr1); print Dumper( \@surprise );
Just re-read grep. Remember that grep uses a boolean filter - the first argument - to select values out of a list. Your 'filter' - $var1 - always evals to TRUE.

If seems that what you are looking for might be something like
use strict; use warnings; my @arr2 =('a', 'b'); my @arr1 = ('a'); my %reference = map { $_ => 1 } @arr1; for my $var1 (@arr2) { print "match $var1\n" if exists $reference{$var1}; }
Hth.