$Word{length$_} .= $_ while (<>); # ... print OUT $Word{$_};