in reply to Removing trailing asterisk from lines with regex

my @lines = ("foo*\n", "foo* \n", "foo* \n"); for my $line (@lines) { $line =~ s/\*\s$//; print "($line)\n"; }
For the first input, the * and newline are removed. For the second input, the * and trailing space are removed, but the newline is left there. For the third input, nothing is removed. You might want to use this substitution instead:
$line =~ s/\*\s*$//;