How big are the other files? If you don't mind loading them into memory:
use 5.006; # Uses "open" syntax introduced in Perl 5.6.0. use strict; use warnings; my $output_file_name = shift(@ARGV); my $main_file_name = shift(@ARGV); my @other_file_names = @ARGV; my @data; foreach (@other_file_names) { open(my $fh_in, '<', $_) or die("Unable to open input file $_: $!\n"); while (my $line = <$fh_in>) { # Keep the \n on $line. chomp(my $chomped_line = $line); my @fields = split(/,/, $chomped_line); foreach my $idx (0..$#fields) { # Saves a reference instead of a copy to save memory. push(@{$data[$idx]{$fields[$idx]}}, \$line); } } } { open(my $fh_in, '<', $main_file_name) or die("Unable to open input file $main_file_name: $!\n"); open(my $fh_out, '>', $output_file_name) or die("Unable to open output file $output_file_name: $!\n"); while (my $line = <$fh_in>) { print $fh_out ($line); chomp($line); my @fields = split(/,/, $line); foreach my $idx (0..$#fields) { if ($data[$idx]{$fields[$idx]}) { foreach (@{$data[$idx]{$fields[$idx]}}) { print $fh_out ($$_); } } } } }

Untested. You didn't specify what to do And you should probably use Text::CSV_XS instead of splitting yourself.

Update: Fixed compilation errors.


In reply to Re: How to combine multiple files together by ikegami
in thread How to combine multiple files together by xspikx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.