in reply to Error while taking 'Scalar of scalar'

The coloring() subroutine returns a string (simple scalar) contains the color name, which you store in $genecolor scalar variable. You pass in the filledRectangle() method the $$genecolor, which means you're trying to dereference $genecolor. But $genecolor is a simple scalar, not a reference, hence the error.

If you look up the perldiag, or in your local system, man perldiag or perldoc perldiag, you'll find the error explanation:

Can't use string ("%s") as %s ref while "strict refs" in use (F) Only hard references are allowed by "strict refs". Symbolic ref +erences are disallowed. See perlref.
If you put use diagnostics; line near the top of your program, it will give you the error explanation automatically.

I don't know what the filledRectangle() method expects as the fifth argument. If it says a SCALAR reference or a reference to a SCALAR then you must pass it as:

$im->filledRectangle($X1,$Y1-20,$X2,$Y2,\$genecolor);
Otherwise, if it says nothing about references, then just pass in the variable as is:
$im->filledRectangle($X1,$Y1-20,$X2,$Y2,$genecolor);

Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!