Please read my original reply again. My suggested fix was not to replace ($x==4) with ($x==0) but to replace my $x; with my $x=0;