#! perl use strict; use warnings; use Capture::Tiny 'tee_merged'; my $outfile = 'sqr.txt'; my $stdout = tee_merged \□ open(my $fh, '>', $outfile) or die "Cannot open file '$outfile' for writing: $!"; print $fh $stdout; close $fh or die "Cannot close file '$outfile': $!"; sub square { print "Enter a number (0 to quit): "; my $n = ; chomp $n; while ($n) { printf "%f squared is %f\n", $n, $n * $n; print "Enter a number (0 to quit): "; $n = ; chomp $n; } print "Bye!\n"; }