#!/usr/bin/perl use strict; use warnings; # Set aside a place to store the data between read and write phases my @OutputBuffer = (); # Read whole file into memory, since we will eventually overwrite it # Often called "slurp" open(my $inputFH, "<", "uuu.txt") || die "cant open the original file"; while (my $inputLine = <$inputFH>) { print $inputLine; # Since we're here, let's process the data # Often called "digest" chomp $inputLine; $inputLine =~ s/\s//g; push @OutputBuffer, $inputLine; } close $inputFH; # Destroy old file and rewrite with new data # Often called "spew" open(my $outputFH, ">", "uuu.txt") || die "cant open the new file"; foreach my $outputLine (@OutputBuffer) { print $outputFH "$outputLine\n"; } close $outputFH; # Fini exit;