my smartish_sub { my ($colour) = @_; # Here is the hash with some constants based on the colour. You can put this hash anywhere really. my %colour_indexes = ( red => ( equal_cond => 11, button_ind => 1, make_colour_ind1 => 1, make_colour_ind2 => 2, ), blue => ( equal_cond => 1, button_ind => -1, make_colour_ind1 => -1, make_colour_ind2 => -2, ) ); # rest of code is written to use the hash references keyed on the colour, much like moritz described ...