#!/usr/bin/perl use strict; use warnings; my %FileInfo1 = (); my ($inputFilename1, $inputFilename2, @otherParameters) = @ARGV; # Read File 1 to Hash open INPUT_FILE1, '<', $inputFilename1; while (my $inputBuffer1 = ) { chomp $inputBuffer1; my ($key, $data) = split /\|/, $inputBuffer1, 2; $FileInfo1{$key} = $data; } close INPUT_FILE1; # Read File 2 and Compare open INPUT_FILE2, '<', $inputFilename2; while (my $inputBuffer2 = ) { chomp $inputBuffer2; my ($key, $data) = split /\|/, $inputBuffer2, 2; if (!defined $FileInfo1{$key}) { print "$key not found in $inputFilename1\n"; } elsif ($FileInfo1{$key} ne $data) { print "$key data does not match\n"; delete $FileInfo1{$key}; } else { print "$key - OK\n"; delete $FileInfo1{$key}; } } close INPUT_FILE2; foreach my $leftoverKey (keys %FileInfo1) { print "$leftoverKey not found in $inputFilename2\n"; } exit; __END__ C:\Steve\Dev\PerlMonks\P-2013-10-08@1245-TwoFile-Keyed-Compare>type test*.dat test1.dat A001|Steve|45 A002|George|32 A003|Alice|24 test2.dat A001|Steve|45 A003|Alice|23 A004|Mike|48 C:\Steve\Dev\PerlMonks\P-2013-10-08@1245-TwoFile-Keyed-Compare>perl cmpfiles.pl test1.dat test2.dat A001 - OK A003 data does not match A004 not found in test1.dat A002 not found in test2.dat