in reply to Removing the space in a string

save the spaces from the beginning, save the spaces from the end, then remove spaces in the middle

Replies are listed 'Best First'.
Re^2: Removing the space in a string
by Anonymous Monk on Oct 16, 2015 at 02:00 UTC
    #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; my $msg = NoMiddleSpaces( ' i t s a r a c e ' ); dd( $msg ); sub NoMiddleSpaces { my( $start, $middle, $end ) = $_[0] =~ m{^(\s*)(.*?)(\s*$)}is; $middle =~ s{\s+}{}g; return "$start$middle$end"; } __END__ " itsarace "