You don't need to load your whole file into memory, especially not twice (if I understand correctly your code). Simply read your file line by line, count your aninoacids on the current line and then go to the next line and continue the coun ting. This way you'll have no memory problem counting elements even in GB files. One small additional point:
if($j!=/^>/)
I am not exactly sure what you intend there, but it probably does not do what you want. Also:
if(exists $count{$_})
{
$count{$_}++;
}
else
{
$count{$_}=1;
}
can be replaced simply by:
$count{$_}++;