in reply to matching between 1 to 8 digits but not more

I think you want to add anchors to your regex --
if($Number =~ m/^\d{1,8}$/){ $N = $Number; } else { print("line has more than 8 digits!\n"); }
This seems to satisfy the requirement -- '12345678' and '123456' don't print; '12345654321' does.

----
I Go Back to Sleep, Now.

OGB