select UserName from table where UserName <> '' and UserName not like 'deleted%' #### #! perl -w use strict; my %fhs; while( <> ) { my $char = substr $_, 0, 1; if( not exists $fhs{ $char } ) { open $fhs{ $char }, '>', "names.$char" or die $!; } print { $fhs{ $char } } $_; } #### #! perl -w use strict; for my $fname ( glob 'names.*' ) { my %uniq; open my $fh, '<', $fname or die $!; while( <$fh> ) { print unless exists $uniq{ $_ }; $uniq{ $_ } = 1; } } #### mysql --quick < getnames.sql | perl partNames.pl perl uniqNames.pl > uniqedNames.txt