It looks like
SpeechSynthesizer.GetInstalledVoices returns something like an array, and you converted that to a hash pointing to array indexes. Why not simply use the
array, and let
List::Util's
first give you the index directly? For your problem with index 0, replace the first array element with something unmatchable, and if
first returns
undef, it's the case where you have to use 0 anyway.
my @voices = ...(whatever you do to get the voices array)
my $voicezero = $voices[0]; # if name of voice needed later
$voices[0] = 'least-liked';
my $voice = first { m/$language/ } @voices || 0;
$voices[0] = $voicezero; # if name of voice needed later