in khen1950fx's code my $dev = find_device($ARGV[0]); says that the name "wifi" printed in the error message is retrieved from $ARGV[0]. You call your device wlan0 not wifi. Maybe try wlan0 as the argument?