use PDL::LinearAlgebra; sub ltm { my ($size, $strictly) = @_; my $ltm = ones($size,$size)->tricpy(1); $strictly ? $ltm - identity($size) : $ltm; }