in reply to Problem with reading the total file into variable

Update: Hah! Brother Athanasius is nimbler of finger (not to mention grey matter) ...

As Corion points out, <MYFILE> is a filehandle from which you read and process one line at a time; it doesn't represent a line itself. A corrected version of your code is below.

[00:28][nick:~/monks]$ cat 1139778.txt foo bar baz qux
#!/usr/bin/perl use strict; use warnings; # Don't hard-code filenames in logic code my $file = '1139778.txt'; # Use the three-argument form of open() ... open( my $MYFILE, '<', $file ) or die "Failed to open $file: $!\n"; # ... and always check for +success # Use parentheses to show we want the whole list of lines my $data = join '', (<$MYFILE>); print "Using \$data:\n$data\n\n"; # Go back to the beginning of the file seek $MYFILE, 0, 0; # No parentheses so we get one line at a time print "Using \$line:\n"; while ( my $line = <$MYFILE> ) { # chomp; # No need to chomp if you are printing the file out again print $line; } close $MYFILE or die "Failed to close $file: $!\n"; __END__
Output:
[00:29][nick:~/monks]$ perl 1139778.pl Using $data: foo bar baz qux Using $line: foo bar baz qux

Hope this helps! Make sure you understand it all before you continue :-)

The way forward always starts with a minimal test.