perl -l @_=sort@_;$"='?';push@{$,[length]},$_ for grep{(join'',sort/./sg)=~/$\@_?$/};@{pop@,}