sub improved { my $c = ord(1); my $temp = join $c, @array2; @array1 = grep { -1==index($temp, $c . $_ . $c ) } @array1; }