sub good_sub_name_here { my ($color, $other_color) = @_; if ($old_color eq $color) { if ($_ == 1) { alert(1); } elsif ($button[$_-1]->cget(-background) eq $color) { alert(2); } elsif ($_ >= 2 && $button[$_-1]->cget(-background) eq $other_color && $button[$_-2]->c +get(-background) ne "white") { alert(3); } elsif ($button[$_-1]->cget(-background) eq "white") { make_color ($color, $_-1); make_blank ($_); check_win(); } else { make_color ($color, $_-2); make_blank ($_); check_win(); } } } # and call it: good_sub_name_here(qw(blue red)) good_sub_name_here(qw(red blue))