#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Carp; sub gen_triangles { my $max = shift || 10; my @set; for my $c (1..$max) { for my $b (1..$c) { for my $a (1..$b) { push @set, [$a, $b, $c] if $c**2 == $b**2 + $a**2; } } } return \@set; } print Dumper gen_triangles;