in reply to argument to delete function

whether we can write subroutines which can detect the scalar and array element

As the delete builtin can syntactically only be applied to array or hash elements, I'm not sure what (and why) you'd want to detect...  Could you elaborate on your use case?