I might use the Text::CSV module to parse and compose CSV, perhapse something like the following:

use strict; use warnings; use Data::Dumper; use IO::String; use Text::CSV; my $file1 = IO::String->new(<<EOF) or die "$!"; username, date_modified 2010-nhw-es-ea-285, 2012-10-10 aab.external.audit.-.bvr.verif.externes, 2012-02-22 aashee.aziz, 2012-01-27 abbas.rangwala, 2012-01-27 abbie.gardner, 2012-09-10 ab.border-frontiere, 2012-08-11 abdool.yasseen, 2012-01-31 abdullah.aboukarr, 2012-08-10 abdullahi.sheikh, 2012-02-28 EOF my $file2 = IO::String->new(<<EOF) or die "$!"; fullname, branch aaron.northway, CHIEF FINANCIAL OFFICER BRANCH aashee.aziz, HEALTH PRODUCTS AND FOOD BRANCH abbey.klugerman, HEALTHY ENVIRONMENTS AND CONSUMER SAFETY BRANCH abby.hoffman, STRATEGIC POLICY BRANCH abderrahim.boussanni, CHIEF FINANCIAL OFFICER BRANCH abdiaziz.nur, HEALTHY ENVIRONMENTS AND CONSUMER SAFETY BRANCH abdool.yassin, HEALTH PRODUCTS AND FOOD BRANCH abdoulie.manjang, N/A abdullah.hassen, HEALTH PRODUCTS AND FOOD BRANCH abdullah.patel, REGIONS AND PROGRAMS BRANCH asdf "asdf" asdf,, EOF my $csv1 = Text::CSV->new({ binary => 1, allow_whitespace => 1, sep_char => ',', }); my %date_modified_by_username; $csv1->column_names( $csv1->getline($file1) ); # get header line while(my $href = $csv1->getline_hr($file1)) { $date_modified_by_username{$href->{username}} = $href->{date_modif +ied}; } my $csv2 = Text::CSV->new({ binary => 1, allow_whitespace => 1, sep_char => ',', eol => "\n", }); $csv2->print(\*STDOUT, [ qw{username branch date_modified} ]); $csv2->column_names( $csv2->getline($file2) ); # get header line while(my $href = $csv2->getline_hr($file2)) { my $date_modified = $date_modified_by_username{$href->{fullname}} || 'unknown'; $csv2->print(\*STDOUT, [ $href->{fullname}, $href->{branch}, $date_modified ]); }

With your sample data this produces:

username,branch,date_modified aaron.northway,"CHIEF FINANCIAL OFFICER BRANCH",unknown aashee.aziz,"HEALTH PRODUCTS AND FOOD BRANCH",2012-01-27 abbey.klugerman,"HEALTHY ENVIRONMENTS AND CONSUMER SAFETY BRANCH",unkn +own abby.hoffman,"STRATEGIC POLICY BRANCH",unknown abderrahim.boussanni,"CHIEF FINANCIAL OFFICER BRANCH",unknown abdiaziz.nur,"HEALTHY ENVIRONMENTS AND CONSUMER SAFETY BRANCH",unknown abdool.yassin,"HEALTH PRODUCTS AND FOOD BRANCH",unknown abdoulie.manjang,N/A,unknown abdullah.hassen,"HEALTH PRODUCTS AND FOOD BRANCH",unknown abdullah.patel,"REGIONS AND PROGRAMS BRANCH",unknown

In reply to Re: Merging Two CSV files Based on Two Columns by ig
in thread Merging Two CSV files Based on Two Columns by TheCanadian

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.