Thanks a lot for the suggestions!
Yes, it's not an alignment rather a collection of fasta sequences that I want to align but only after removing shorter sequences. Sorry about the confusion.
I am familiar with seqtk but for that I need to state cutoff length, which varies for different genes. Proportion instead of fixed cutoff length would be better but couldn't locate proportion in the seqtk manual.
I was able to resolve the issue with running your script. The multi-fasta needs to be aligned before running the script to drop the shorter sequences. Thank you for sharing the script. It was very helpful!