use GD; sub getindex { my $image = shift; my $index = $image->colorExact(@_); $index == -1 ? $image->colorAllocate(@_) : $index; }