$txt = "This is a string"; $count = $txt =~ tr/ //; #counts all spaces $count = () = $txt =~ m/\s/g; #counts all whitespace characters $count = () = $txt =~ m/\s+/g; #counts whitespace occurences (default [split] behavior) #### $count = tr/ // for ($txt);