in reply to Picking up information coming out of a loop

You are creating a lexically-scoped variable @line_no within your while() loop with this:

push (my @line_no, $.);

Should be
push (@line_no, $.);

as per the elsif() later within the block.