Originally Posted by dsb
I think you're asking why your second attempt wasn't working? If so, I think it's this bit:
                         foreach my $i(@$arrayref2){
                            if($j == $i){
                                if($count < $arraysize1) { next; }
                                else { 
                                	return 1; 
                            else { return 0; }
You should be able to step through it mentally to really see what's happening, and practicing that ought to help you debug your own code in the future.

starting with the beginning if the inner foreach loop.
1. set $i = 1 ($j is already set to 1 at this point)
2. evaluate $i == $j, which is true so enter that block
3. evaluate $count < $arraysize1, which is true, so enter that block.
4. next, go to the next pass through the inner foreach loop
5. (back at start of inner foreach loop) set $i = 2
6. evaluate $i = $j, which is false ($j still set to 1), so go to the false block, which returns 0.

ooooo. I see. Thanks a lot, man. I didn't think anyone was going to answer it.