my $file = '/path/to/file'; open my $fh, '>', $file or die $!; print $_,"\n" for @dirs; close $fh;