use v5.16; use warnings; open(my $FH, ">", "input.txt") or die "Can't open < input.txt: $!"; my $i; for (0 .. 3) { $i = int(rand(10)); say $i; say $FH $i } close $FH;