#!/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>; }