How do you use text normalization with a short example?

Text Normalization, Perl, String Manipulation, Data Preprocessing
This example demonstrates how to use text normalization in Perl to clean and prepare text data for analysis.

#!/usr/bin/perl
use strict;
use warnings;

# Sample text that needs normalization
my $text = "Hello, World! Welcome to Perl.  \n\nThis is a test... with extra spaces.   ";

# Normalizing text: trimming whitespace and removing special characters
$text =~ s/\s+/ /g;            # Replace multiple spaces with a single space
$text =~ s/[^\w\s]//g;         # Remove special characters
$text =~ s/^\s+|\s+$//g;      # Trim leading and trailing whitespace

print $text;  # Output: "Hello World Welcome to Perl This is a test with extra spaces"
    

Text Normalization Perl String Manipulation Data Preprocessing