in reply to using UID-MIN

This is just a guess, based on the error message:
It looks like the leading space implies improper parsing - try this:
system ("useradd", '-K','UID_MIN=2000', "-g $gid", "-m", "-p $hash", " +$user");

        If your eyes hurt after you drink coffee, you have to take the spoon out of the cup.
              -Norm Crosby