in reply to comparing fields within pipe-separated lines

Use split.
my $field = 5; # the field to compare open(FIRST, "> $file1") or die "Can't open $file1: $!"; open(SECOND, "> $file2") or die "Can't open $file2: $!'; while (defined(my $first = <FIRST>) { defined(my $second = <SECOND>) or last; my @first = split(/\|/, $first); my @second = split(/\|/, $second); if ($first[$field] eq $second[$field]) { # mark match } else { # mark no match } }
It's possible to shorten that somewhat by list slicing split, but this'll do for now. Be aware that the first element of a list has an index of 0.