# Assume that %file has the filename for each field in your # table and @fields has the list of field names. my @fhs; for my $field (@fields) { open(my $fh, "<", $file{$field}) or die "Can't open '$file{$field}: $!"; push @fhs, $fh; } while (1) { my $did_read; my @data; for my $fh (@fhs) { my $rec = <$fh>; if (defined($rec)) { $did_read++; push @data, $rec; } else { push @data, ""; } } if ($did_read) { insert_data(@data); } else { # Came to the end of all data streams last; } }