Thanks for all the suggestions for my sort problem. I ended up using something like this: dbmopen (%KEYED,"$TEMPFILE"..); while (<INFILE>){ Get $line; Get $key; $KEYED{$key}=$line; push(@keylist,$key); }