sub double_for { $CODE_REFERENCE = $_[0]; for $i (1..$row_count) { for $j (1..$col_count) { &$CODE_REFERENCE($i, $j); } } } double_for(\&mysub);