in reply to print and extract the line

I think you can also use "$." in place of "$count" in your code.
"man perlvar"

$. Current line number for the last filehandle accessed.