use strict; use warnings; use Set::CrossProduct; my @ops = qw( * + - / ); my $expr = '2006 == ' . join ' %s ', 1 .. 9; my $xp = Set::CrossProduct->new( [ map \@ops, $expr =~ /%s/g ] ); while( my @attempt = $xp->get ) { my $attempt = sprintf $expr, @attempt; print $attempt, "\n" if eval $attempt; }