Which version of perl? Early versions did not necessarily return filenames in alphabetical order on all platforms. You might be better off using: @files = glob("$path*A[0-9]*.pkl"); or iterate through that from a foreach loop, rather than using glob in scalar context.