my %colorsets = ( samn => [ "#A5A5A5", "#84B594", "#84A5C6", "#DE6BA5" ], atari => [ "#00ff00", "#8fbc8f", "#ffcc00", "#000000", "#33cc00", "#330099", "#363636" ], ); my $set = $ENV{QUERY_STRING}; my $colors = (defined $set and exists $colorsets{$set}) ? $colorsets{$set} : $colorsets{samn}; my $numcolors = @$colors; for (0 .. $totcells) { my $cellcol = $colors->[ rand $numcolors ]; # the rest as above }