my %file2; open my $file2, '<', shift or die; while ( my $line = <$file2> ) { chomp($line); # Do not keep the "\n" at the end of $line ++$file2{$line}; } open my $file1, '<', shift or die; while ( my $line = <$file1> ) { SEARCH: for my $search (keys %file2) { print $line and last SEARCH if index $line, $search > -1; # Edit: GotToBTru pointed out I forgot "index" } }