before addressing the core issue, i see a couple immediate code items:
- avoid using $a and $b as variable names -- they have special meaning (see sort)
- In all of these: elsif ( $A[$b] = $T[$b] ) { you are using the assignment operator instead of the equality operator ==, so this code will not do what you want..
- not wrong as-is, but note it's "more perl-ish" to write loops like (multiple ways to write this): foreach my $b ( 0 .. $w-1 ){
i'll update shortly after looking at the actual issue.. my initial reaction is that the solution probably involves hashes instead of arrays (and maybe a function for "find-the-max" instead of that if/else ladder).