#!/ust/bin/perl use strict; use warnings; my $file='./test.txt'; open (my $in, '+<', $file) or die("ERROR OPEN $file ($!)\n"); while(<$in>) { if(/TESTWORT1/ .. /---/) { print "TESTWORT1 found\n"; seek($in, 0,0); truncate($in,0); } else { print "TESTWORT1 not found\n"; } } close($in); print "EXIT\n";