#!/usr/bin/perl use strict; use warnings; my $number_of_cols_per_file =3; my @data; #this is a 2-D Array while (my $line = ) { chomp $line; my (@cols) = split (':', $line); push @data, \@cols; } my $file_num=1; while (@{$data[0]} > 1) # Any Columns after the name_column left? { # generate the next file # This print would change to a "file open" statement for # file_num, n... print "File Number = ",$file_num++,"\n"; foreach my $row_ref (@data) { my $row_name=$row_ref->[0]; my @data_cols = splice (@$row_ref,1,$number_of_cols_per_file); print join(":", $row_name, @data_cols), "\n"; } } =Prints: File Number = 1 row_nameA:col2a:col3a:col4a row_nameB:col2b:col3b:col4b File Number = 2 row_nameA:col5a:col6a row_nameB:col5b:col6b =cut __DATA__ row_nameA:col2a:col3a:col4a:col5a:col6a row_nameB:col2b:col3b:col4b:col5b:col6b