while(<>){ chomp($_); $len = length($_); open(OUTPUT,">>${len}.words"); print OUTPUT "$_\n"; close(OUTPUT); }