#!/usr/bin/env perl use warnings; use strict; use open qw/:std :utf8/; # STDIN/OUT/ERR in utf8 use Tie::File; # normally "tie my @file1, 'Tie::File', '/tmp/file1' or die ...", # but we need utf8, note the following opens the files read-only open my $fh1, '<:utf8', '/tmp/file1' or die $!; tie my @file1, 'Tie::File', $fh1 or die $!; open my $fh2, '<:utf8', '/tmp/file2' or die $!; tie my @file2, 'Tie::File', $fh2 or die $!; for (@file1) { my ($l1, $n1) = /^(\w+)\s+(\S+)\s*$/ or die "Bad file1 line: $_"; for (@file2) { my ($l2, $n2) = /^(\w+)\s+(\S+)\s*$/ or die "Bad file2 line: $_"; print "$l1 from FILE1 with number $n1 ", "and $l2 from FILE2 with number $n2 "; if ($l1 eq $l2) { print "match\n" } else { print "DO NOT match\n" } } } untie @file1; close $fh1; untie @file2; close $fh2;