in reply to Re: Conditional replace
in thread Conditional replace

Your last print has a typo :-) your logic is backwards :-) and its simpler IMO to say:
my $add_at_end; while (<IN>) { $add_at_end = 1 unless s/str1/str2/; print OUT; } print OUT "text" if $add_at_end;
Update:And I had a typo also. Fixed mine first :-)