$Start_Str = shift @ARGV; # to pass starting string $End_Str = shift @ARGV; # to pass ending string foreach $file (@ARGV) # to repeat the task for each file { $Flag = 0; $filename = "Final_".$file; open(DATA, ">$filename"); # file to write data to if (open(INFO, $file)) { @line = ; # assigns lines to array foreach $lines (@line) { # go through each line in file if (($lines=~ /$Start_Str/) || ($Flag == 1)) { $Flag = 1; if ($lines=~ /$End_Str/ ) { $Flag = 0; } } else { print DATA ($lines); } } } } print "Parsing is completed"; close(INFO); # closes file close(DATA);