#!/usr/bin/perl # http://perlmonks.org/?node_id=1215296 use strict; use warnings; while() { /^~/ 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.