sub up{ # indent to evidentiate the recursive function level # using the last index of the arguments array my $ind = ' ' x $#_ x 4; print $ind."\@_ = [@_]\n"; my ($row, $col) = split /-/, $_[0]; # if the first argument is 0-0 we are arrived to # the upper edge: time to return the result if ($_[0] eq '0-0'){ print $ind."RETURNING: \@_ is a valid path [@_]\n"; return "@_\n" } else{ # check A if ($row * $col > 0){ # show what happens if check A pass print $ind."$row * $col > 0 ". "&& up(",$row-1,'-',$col-1,", ",(join ', ',@_), ') # decremented both row and column are passed plus original @_ ',"\n"; } else{ print $ind."$row * $col > 0 is FALSE...\n"; } # execute the code if check A pass as shown above ($row * $col > 0 && up( ~-$row . '-' . ~-$col, @_ ) ) . ( # check B eval{ # show what happens if check B pass if ($row > $col){ print $ind."$row > $col ". "&& up(",$row-1,'-',$col,", ",(join ', ',@_), ') # decremented row and original column are passed plus original @_ ',"\n"; } else{print $ind."$row > $col is FALSE...\n"} # the eval block return empty string # to not pollute the output of the function ''; } ). # execute the code if check B pass as shown above ($row > $col && up( ~-$row . '-' . $col, @_ ) ); } }