#!/usr/bin/env perl use strict; use warnings; use Algorithm::Loops qw(NextPermuteNum); use Data::Dump; use feature qw(say); my @n = sort { $a <=> $b } ( 1, 1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7, 8, 11, 12, 13, 14, 14, 15 ); my $m3 = qr/(.)\1\1/; my $m2 = qr/(.)\1/; do { my $s = pack( "(A*)*", @n ); if ( $s =~ /($m3)/ ) { say $1; sleep 1; goto PERMUTE; } if ( $s =~ /($m2)/ ) { goto PERMUTE; say $1; sleep 1; } say join " ", @n; PERMUTE: ; # empty statement to attach the label to } while (NextPermuteNum( @n )); __END__