$file = ; #### local $/ = undef; $file = ; #### $file = join("", ); #### foreach $this_paragraph (@paras) { .... } #### foreach my $this_paragraph (@paras) { my @split_para = split(/:/, $this_paragraph); if( $split_para[1] = $KWD ) { print $this_paragraph; } } #### foreach my $this_paragraph (@paras) { if( $this_paragraph =~ /^$KWD:/s ) { print $this_paragraph; # This works if the paragraph looks like 'KEYWORD: ...' } } #### foreach my $this_paragraph (@paras) { if( $this_paragraph =~ /:$KWD\b/s ) { print $this_paragraph; # This works if the paragraph looks like '.... :KEYWORD ...' } }