how can i remove white space at the beginning of a word?

You can remove the white spaces from the names in the split regex.

So your code will become:

open DATA, "<", "name.txt";
my @file = <DATA>;

foreach my $name (@file) {
    chomp $name;

    # find ‘Mr.’ and ‘Ms.’, then ignore them
    my @arr = split(/M.\.\s+/g, $name);

    print @arr,"\n";

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top