# Capture the first five words including whitespace. if ( $text =~ / (\S+ \s+ \S+ \s+ \S+ \s+ \S+ \s+ \S+ )/x ) { # The regex extracted the first five words $text = "$1 ..."; # Shrink any internal whitespace $text =~ s/\s+/ /g; }