#!/usr/bin/perl use strict; use warnings; open(FH, "<", "test.txt"); my @file = ; close(FH); open(FH, ">", "test.txt" ); foreach (@file) { s/^(\s+)//g; print FH $_; } close FH;