in reply to /g option not making s// find all matches

Unless it's homework, this might be simpler.

#!/usr/bin/perl # http://perlmonks.org/?node_id=1215296 use strict; use warnings; while(<DATA>) { /^~/ and tr/_/+/; print; } __DATA__ A line with an_underscore. A line with_two_underscores. ~A line with an_underscore starting with a tilde. ~A line with_two_underscores starting with a tilde.