#!/usr/bin/perl use strict; use Data::Dumper; my (@total_words, %record_file_of); my $counter = 0; my $num_of_files = 3; @total_words = split while (); my $words_per_file = int( scalar @total_words / $num_of_files ); for my $i (0 .. $#total_words) { $counter++ if ( $i % $words_per_file == 0 ); push( @{ $record_file_of{$counter} } , $total_words[$i] ); } print Dumper \%record_file_of; __DATA__ This is a test of words. This should be divided into equal files.