sub leftover { my ($full, $part) = @_; my @count; $count[ord $1]++ while $full =~ /(\w)/g; while ($part =~ /(\w)/g) { return undef if --$count[ord $1] < 0; } my $return; $count[$_] and $return .= chr($_) x $count[$_] for 0..$#count; $return; }