#!/usr/bin/perl -w use strict; use IO::File; my $string = "1 2 3 4 5 6 7 8"; my $fh = IO::File->new(">/tmp/output.txt"); die "Failed to open output file $!" unless defined $fh; say $fh $_ for split /\s/, $string; $fh->close;