in reply to Pulling white space off before/after string?

If you want to make the changes on the fly you could use this with your regex. The .bak specifies a backup file extension, so you have an original copy. You can change it as you like or remove it if you wish no backup. The nice part is both operations are performed at once. You could also do that like above as so by looping through the lines of the file. Variable Substitution
$my_data_line =~ s/^\s+|\s$+//g;
Modify file inplace and make a backup copy to filename.html.bak the easy way.
perl -p -i.bak -e 's/^\s+|\s$+//g' *.html

Replies are listed 'Best First'.
Re^2: Pulling white space off before/after string?
by romskie (Initiate) on Aug 30, 2012 at 09:06 UTC
    you probably mean:
    $my_data_line =~ s/^\s+|\s+$//g;