#!/usr/bin/perl use strict; use warnings; my $hr_file = 'HR.txt'; open my $fh, '<', $hr_file or die $!; my (undef, @hdr_hr) = split /,/, <$fh>; chomp @hdr_hr; my %hr_data; while (<$fh>) { chomp; my ($id, @rest) = split /,/; @{ $hr_data{$id} }{@hdr_hr} = @rest; } close $fh or die $!; my $ad_file = 'AD.txt'; open $fh, '<', $ad_file or die $!; my (undef, @hdr_ad) = split /,/, <$fh>; chomp @hdr_ad; @hdr_ad ~~ @hdr_hr or die "Uncompatible headers between HR and AD files\n"; my %ad_data; while (<$fh>) { chomp; my ($id, @rest) = split /,/; @{ $ad_data{$id} }{@hdr_ad} = @rest; } close $fh or die $!; for my $id (sort keys %hr_data) { next unless exists $ad_data{$id}; for my $hdr (@hdr_hr) { my $description_hr = $hr_data{$id}{$hdr}; my $description_ad = $ad_data{$id}{$hdr}; print "$id,$hdr,$description_hr\n" unless $description_hr eq $description_ad; } }