use warnings; use strict; my $Fn1 = shift; my $Fn2 = shift; die "Usage:\n" . "hash4Ans \n\n" . "file1 and file2 are the files to compare\n\n" if ! defined $Fn1 or ! defined $Fn2; my %File1; my %File2; open (inFile, "$Fn1") or die "Unable to open $Fn1 $!\n"; while () { chomp; my ($Key, $Tail) = /^((?:\w+\s){4})(.*)/g; $File1{$Key} = "$.:$Tail"; } close inFile; open (inFile, "$Fn2") or die "Unable to open $Fn2 $!\n"; while () { chomp; my ($Key, $Tail) = /^((?:\w+\s){4})(.*)/g; $File2{$Key} = "$.:$Tail"; } close inFile; my $Key; foreach $Key (%File1) { next if ! defined $File2 {$Key}; my ($Ln1, $Tail1) = $File1 {$Key} =~ /(\d)+:(.*)/g; my ($Ln2, $Tail2) = $File2 {$Key} =~ /(\d)+:(.*)/g; print "Match in line $Ln1 from $Fn1 with line $Ln2 from $Fn2:\n"; print "$Key$Tail1\n"; print "$Key$Tail2\n"; my ($Words1) = $Tail1 =~ /(?:\S+\s+){3}(.*)/g; my ($Words2) = $Tail2 =~ /(?:\S+\s+){3}(.*)/g; print "Note: Tailing word mismatch in previous pair.\n" if $Words1 ne $Words2; print "\n"; } print "Done.\n";