$ perl -we 'q{xxx.xxx} =~ /\b(xxx\.xxx)\b/; print "|$1|\n"' |xxx.xxx| $ perl -we 'q{.xxx} =~ /\b(\.xxx)\b/; print "|$1|\n"' Use of uninitialized value $1 in concatenation (.) or string at -e line 1. || #### $ perl -we 'q{xxx.xxx} =~ /(?## $ cat log_to_read.txt 1 abc 2 def 3 ghi 4 jkl 5 def 6 ghi 7 abd 8 abcdefghi 9 abc def ghi 10 $@% 11 \$\@\% $ cat keys_to_find.txt abc def ghi $@% #### #!/usr/bin/env perl use strict; use warnings; use autodie; my $log_search_re; { open my $keys_fh, '<', 'keys_to_find.txt'; $log_search_re = qr/(?x: (? ]} ) (?!\w) )/; } { open my $log_fh, '<', 'log_to_read.txt'; open my $out_fh, '>', 'log_lines_matched.txt'; /$log_search_re/ && print $out_fh $_ while <$log_fh>; } #### $ cat log_lines_matched.txt 1 abc 2 def 3 ghi 5 def 6 ghi 9 abc def ghi 10 $@%