#!/usr/bin/perl -w use strict; my %Word; my $File; # Fill the hash/list here, ignoring the chomp push @{$Word{length$_}},$_ while (<>); # Itterate over the different lenghts of words for (keys %Word) { # This is what is called a dirty hack, subtract # one from the length of the string to compensate # for the '\n' (but hey, it saves a chomp for every word :) ) $File=$_-1 . ".mine"; # Write the file open OUT,">$File" or die "Cannot open $File.mine: $!\n"; print OUT @{$Word{$_}}; close OUT; };