in reply to Simple comparison of 2 files

#!/usr/bin/perl # http://perlmonks.org/?node_id=1168667 use strict; use warnings; my $file1 = <<END; A 1_1 A 1_2 B 1_3 C 1_4 END my $file2 = <<END; A 2_1 B 2_2 END "$file1\0\n$file2" =~ / ^(\S+)\ +(\S+)\n .* \0\n .*? ^(\S+)\ +(\S+)\n (?{ print "$1 from FILE1 with number $2 and $3 from FILE2 with number $4 ", $1 eq $3 ? "match" : "DO NOT match", "\n" }) (*FAIL) /msx;

prints your desired output