#!/usr/bin/perl # http://perlmonks.org/?node_id=1211497 use strict; use warnings; sub up { my ($row, $col) = split /-/, $_[0]; return $_[0] eq '0-0' ? "@_\n" : ($row * $col > 0 && up( ~-$row . '-' . ~-$col, @_ ) ) . ($row > $col && up( ~-$row . '-' . $col, @_ ) ); } print up( '3-1' );