This is my perl program
open(MYINPUTFILE, "<sampleinput.txt");
while(<MYINPUTFILE>)
{
my($line) = $_;
chomp($line);
$line =~ tr/[a-z]/[A-Z]/;
print "$line\n";
}
close(MYINPUTFILE);
open(MYOUTFILE, '>sampleoutput.txt');
print MYOUTFILE "$line";
close(MYOUTFILE);


This program is basically supposed to
1) Take text from sampleinput.txt
2) Put it in the string variable called "line".
3) Convert all text in "line" to upper case.
4) Print the result.
5) Store the contents of the "line" string in sampleoutput.txt

The program seems to execute the first 4 steps correctly, but I can't get it to do the 5th i.e store the capitalized contents in the file.

How to make it so?