use strict; use warnings; my $string = "next line is spaces next line is tabs and now some newlines end"; $string =~ s/^\s*$/x/mg; print "$string\n"; #### next line is spaces x next line is tabs x and now some newlines xx end