porting the sort_fasta logic to perl (first step towards rewriting)