perl -le'%h=(), undef @h{split"",$_}, keys %h == 3 and print for "0000".."9999"' #### #!/usr/bin/perl -lw use strict; for ( '0000'..'9999' ) { my %h; undef @h{split'',$_}; keys %h == 3 and print; }