#! perl -sw use strict; my ($oldfirst, $oldc2n3) = ( '', '' ); open WORDS, '<', $ARGV[0] or die $ARGV[0] . $1 . $/; while() { chomp; $_ = lc; my ($first, $c2n3) = /^(.)(..?)?.*/; $first = './' . $first; $c2n3 = substr($c2n3.'__',0,2) if !defined $c2n3 or length($c2n3) < 2; $c2n3 = $first . '/' . $c2n3; if ( ($first ne $oldfirst) or ($c2n3 ne $oldc2n3) ) { mkdir $first if not -e $first; open SUB, '>>', $c2n3 or die $c2n3 . $! . $/; } print SUB $_, $/; ($oldfirst, $oldc2n3) = ($first, $c2n3); print "\r$c2n3:$_ "; }