Here's
another way to do it, if I correctly understand what you want to do. You want to find an index
$i for which
$a[$i] eq $a and $b[$i] ne $b (that is, your condition holds at the same index). So why are you searching the array elements? It's better to search for an appropriate
index!
@indices = grep
{ $a[$_] eq $a and $b[$_] ne $b }
(0..$#a);