Use perror to save the error message repetition