#!/usr/bin/perl use strict; use warnings; die "Usage: $0 input.file\n" unless ( @ARGV == 1 and -f $ARGV[0] ); my $input_file = shift; my $input_byte_count = -s $input_file; { local $/; # set input_record_separator to undef -- switch to "slurp" mode open( I, $input_file ) or die "$input_file: $!"; my $whole_file = ; close I; } if ( length( $whole_file ) < $input_byte_count ) { die "$0: Perl can't read all of $input_file"; } elsif ( length( $whole_file ) > $input_byte_count ) { die "$0: Either -s $input_file is lying, or bytes were added during read\n"; } else { warn "$0: got exactly $input_byte_count bytes from $input_file\n"; } # now, what was it you need to do with $whole_file? ... # to normalize all whitespace to " " (making it just one long line): s/\s+/ /g; print;