my $str = " word1 word2\n word3 word4 word5\n"; print "str before = $str\n"; $str =~ s/(?