in reply to check for contiguous row values

Welcome to the monastery. We are more than happy to help new members of the Perl community learn and grow.
  1. On line 7, your regular expression assumes your data is tab delimited. However, the input file you posted is fixed width. Was this a copy/paste error, or are you unfamiliar with different types of whitespace? In either case, the initial parse failure that this results in can be fixed by swapping \t (the tab character) to \s+ (1 or more whitespace character), assuming column 1 will never contain whitespace. ($n,$p) = $lines =~ /^(\d+)\s+(.+)\n/;

  2. On every iteration of your loop that didn't involve the record break, you reset your @B and @N arrays. Therefore, you can never accumulate enough records to hit your output loop. You likely mean to move those inside your if (scalar(@B) >=2) block.

  3. As per the first issue, you need to change you splits from /\t/ to /\s+/.

Making those changes to your script, I get the following output:

3DKG000004283 3DKG000004543 4 3DiKG000004569 3DiKG000004773 4 3DiKG000005165 3DiKG000005331 2 3DKG000007633 3DKG000007727 4

as well as a number of warnings for uninitialized subtraction. This is not yet your goal, but is working toward it. Further corrections require modifications to your algorithm.

What resources are you using for learning Perl? There are enough wholly unnecessary operations in the above that understanding where you are coming from (languages you know, resources available, ...) would help us guide you toward making this script work as well as improve your own style.