in reply to matching multiple line

Here's a simple script that will do what you're asking. Rather than editing the existing file, it redirects to a new file "text.out". If you need to, simply add a system command to rename text.out to basic.txt. Obviously, there are better/different ways of handling this, but you weren't very specific about your scenario.

-fuzzyping
#!/usr/bin/perl use strict; my $string_to_match = "I dont have money"; my $string_to_insert = "yes thats correct\nbut your should have\nmoney + with you\notherwise it is not\npossible\n"; open(INFILE, "basic.txt"); open(OUTFILE, ">>text.out"); while (<INFILE>) { unless (/$string_to_match/) { print OUTFILE $_; } else { print OUTFILE $_, $string_to_insert; } } close(OUTFILE); close(INFILE); 1;