my $ro_string = " I'm surrounded by spaces! "; for ($ro_string) { # alias $_ to $ro_string for this scope s/^\s*//; # strip leading spaces from $_ s/\s*$//; # strip trailing spaces from $_ } # lose $_ when the scope ends print; # nothing!