$extra = "This is i will place after match\n.an this too"; open (my $fh, '+<', $file); $data = <$fh>; $data = s/(.*entry)\n([^\n]*)\n/$1\n$extra/