use strict; use warnings; my $first_file = shift || 'a.txt'; my $second_file = shift || 'b.txt'; open my $a_fh, '<', $first_file or die "$first_file: $!"; open my $b_fh, '<', $second_file or die "$second_file: $!"; my %second_file; @second_file{map { unpack 'A*', $_ } <$b_fh>} = (); while (<$a_fh>) { print unless exists $second_file{unpack 'A*', $_}; }