in reply to Error using Getopt::Long

Which version of Getopt::Long are you using?
perl -MGetopt::Long -e 'print $Getopt::Long::VERSION'
In the three versions I have access to, the code you have doesn't work in 2.23 and 2.34 but does in 2.36. If your version is less than 2.36 you will have to upgrade it to use this functionality.