if ($data =~ m/.*?.*?(.*?)<\/rstate>/s) { print "found first match! '$1'\n"; #$data=~ s/.*?.*?(.*?)<\/rstate>/$newrstate/s; $data=~ s/$rstate/$newrstate/s; } if ($data =~ m/.*?.*?.*?(.*?)<\/rstate>/s) { print "found second match! '$1'\n"; $data=~ s/$rstate/$newrstate/s; } if ($data =~ m/.*?.*?.*?.*?(.*?)<\/rstate>/s) { print "found third match! '$1'\n"; $data=~ s/$rstate/$newrstate/; } # Print to output file print OUT $data; #### Some text CHANGE_THIS dont change this CHANGE_THIS dont change this DONT CHANGE THIS dont change this CHANGE_THIS dont change this DONT CHANGE THIS