#!/usr/bin/perl use strict; use warnings; my $first = "single_records.txt"; my $second = "multiple_records.txt"; warn "tie-ing $first...\n"; tie my %hsh, 'Tie::File::AsHash', $first, split => qr/\s+/ or die "Problem tying %hash: $!"; open (my $fh, '<', $second) || die "Failed to open $second : $!" ## always check for success on fh while (<$fh>){ my $line = chomp($_); my ($id,) = split /\s+/, $line; ## capture id ## compare to tied hsh of single records if (exists$hsh{$id}){ print "$line matched $id : $hsh{$id}\n"; } } ## tidy up close $fh || die "Failed to close $second : $!"; untie %hsh;