Perl: Pattern to remove words with less than 2 characters.

Hello. I've been thinking about how to go about this. I know I'm close but still does not work. I need to remove any word in that is not at least 2 characters long. I've removed all the non-alphabetic characters already (numbers included). Here's an example:

my $string = "This string is a sample string a e io u";

# Some pattern matching expression here.

print $string . "\n";    

# Output should be "This string is  sample string io"

I tried using something like this below:

$string =~ s/[a-z]{1}//g;

But it doesn't work.

$string =~ s/\b[^ \t]\b//g;
1 Like

Works perfectly!
Thanks rdrtx1.

Alternatively:

$string =~ s/\b\S\b//g;

tyler_durden

Thanks!