toolic gave you a great solution. I just wanted to mention a few minor things:
Internal variable $. could be used instead of $counter. Internal variable $_ could be used in lieu of $line. The print isn't needed after you determine the split worked properly.
Comment on Re: counting unique elements of an array