Read the files line-by-line, split each pair of lines along whitespace, compare the relevant field, and output the lines if they differ:
#!/usr/bin/perl use feature qw/say/; use warnings; use strict; open my $file1, "<", "test1.txt" or die "Could not open first file: $! +\n"; open my $file2, "<", "test2.txt" or die "Could not open second file: $ +!\n"; while(my $line1 = <$file1>) { my $line2 = <$file2>; chomp ($line1, $line2); my ($key1, $num1, $str1) = split /\s+/, $line1; my ($key2, $num2, $str2) = split /\s+/, $line2; if($str1 ne $str2) { say $line1; say $line2; } } close $file1 or die "Could not close first file: $!\n"; close $file2 or die "Could not close second file: $!\n";
There's bound to be shorter, more idiomatic ways of achieving the same thing, but since your userpage indicates you're still new to Perl, you may find this the most instructive/useful.
On an unrelated side note, could you edit your post to use <code> tags for your sample data? See the following nodes for more information on formatting etc.:
In reply to Re: Sorting By Column
by AppleFritter
in thread Sorting By Column
by Roguehorse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |