Converting RGB to hex just involves understanding the decimal representation of RGB. See below for a small perl procedure.

sub RGB2Hex
{
my $r = shift;
my $g = shift;
my $b = shift;
my $dec = 0;

$dec += 256*256*$r;
$dec += 256*$g;
$dec += $b;

return sprintf(“%.6x”, $dec);
}