kschwind@yzerman:~/src/local/j.random> diff red.pl blue.pl 1,2c1,2 < if ($old_color eq "red") { < if ($_ == 11) { --- > if ($old_color eq "blue") { > if ($_ == 1) { 4c4 < } elsif ($button[$_+1]->cget(-background) eq "red") { --- > } elsif ($button[$_-1]->cget(-background) eq "blue") { 6c6 < } elsif ($_ <= 9 && $button[$_+1]->cget(-background) eq "blue" && $button[$_+2]->cget(-background) ne "white") { --- > } elsif ($_ >= 2 && $button[$_-1]->cget(-background) eq "red" && $button[$_-2]->cget(-background) ne "white") { 8,9c8,9 < } elsif ($button[$_+1]->cget(-background) eq "white") { < make_color ("red", $_+1); --- > } elsif ($button[$_-1]->cget(-background) eq "white") { > make_color ("blue", $_-1); 13c13 < make_color ("red", $_+2); --- > make_color ("blue", $_-2); #### 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 ...