I have it working for my IP2M-841EB cameras now with firmware 2.520.AC00.18.R, Build Date: 2017-06-29. I've attached an updated version of your amcrest781.pm file. This one is called amcrest841.pm. I had to change a few things to get it to work.
First, I had to change it to use digest authentication. This requires knowing the realm of the login. On my cameras, this is a string like "Login to
AMC0147447WBBX5UHF" where the last part is the camera serial number. Obviously, this has to change for each individual camera so I used the ControlDevice field in the camera's setup to hold the serial number string for the realm. Also, digest authentication apparently requires the port number in the hostname portion so the ControlAddress field now needs to look something like this:
See attached screenshot. Since ControlAddress needs to follow this format and there is the requirement for the realm, I removed the code that assumed admin:admin as the default credentials as it won't work without the realm anyway.
Finally, I noticed that the UserAgent has to be reset between each individual call to the camera. This might be an authentication token problem that somebody else might know how to straighten out. But for now, each call, reinitializes the UserAgent. I added a couple of subroutines to handle this. Without this, the first sendCmd will work but after that you'll get authentication problems again.
Improvements to my changes are welcome. It's been a while since I did Perl. Too many scripting languages bouncing around in my head.