while () { if (length && /192\.168\./) { $readlines++; } } print($readlines, $/); # prints 3, although you're probably expecting it to be 2. __DATA__ 192.168.0.1 1.192.168.0 12345678901 dfhasfhasdjk 192.168.33.4