http://www.perlmonks.org?node_id=180403

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello fellow monks!

This is a simple question but since I am new here, I felt inclined to ask ( after 5 attempts ). How do I remove leading whitespace from every line in a file then 're-write' the 'new' version back? My 5th attempt is here:

#!/usr/bin/perl -w use strict; use fatal; open( FH, "<test.txt" ); open( FH2, ">test.txt" ); while ( <FH> ) { s/^(\s+)//g; print FH2 $_; } close FH; close FH2;

Warning: This sample does not work.
Thank you,
Alicia