in reply to 'use of uninitialised value' error message
Because in the first snippet you are making use of the value of $sorted_files[0] and in the second you are not.