use File::Slurp 'edit_file'; edit_file { s!.+?!enabled!sg } 'inputfile'; #### this is line 1 this is line 2 enabled this is line 3 enabled this is last line