in reply to Grouping unique lines into a file.

In addition to what has been said by other monks about the lack of clarity of your requirement, I certainly don't understand your code. Especially, you are testing:
if($account=~/$group{$line}/g)
and, whether this conditional returns true or false, you are just doing exactly the same thing. This is unlikely to be your real intent. The way you are populating the %group hash also appears to be inconsistent with the way you are using it in the above conditional, unless I am missing something.