# remove whitespace from beginning and end of $text $text =~ s{^\s+|\s+$}{}g; # do your match if ( $text =~ m{.{3}} ) { }