while( my $line = <> ) { chomp $line; foreach ( $line ) { s/\s*$//; s/\#//g; .... } # foreach $line } # while