use strict; use warnings; my $before = " some text "; ($_ = $before) =~ s/^\s+|\s+$//g; print ">$before<\n"; print "|$_|\n";