http://www.perlmonks.org?node_id=159694


in reply to Alphabetical order with .txt file

Like grep says: use strict; use warnings;

That won't catch your problem though. You're adding a space with @list1[$nk] = "$item1 \n";. Try dropping the space before the newline.

Other concerns:

Update: boo has an excellent point. I just glossed by that point.