While @mob answered your question , I would like to point out that I'm not sure if you want to go the sort uniq path. You still save items that you really don't want to store. In such cases, it is better to use a hash.
Also, when a piece of data is for a row, use a row . The result from find_perms(0345) may surprise you, but find_perms('0345') will not.
Finally, Algorithm::Permute::permute is very fast.
Given these considerations, I would rewrite your code as follows:
use strict; use warnings; use Algorithm::Permute qw( permute ); my $uniq_perms = find_perms('115122345'); sub find_perms { my ($value) = @_; my @digits = split //, $value; my %uniq; permute { $uniq{join('', @digits)} = undef } @digits; return [ keys %uniq ]; }
source share