#!/usr/bin/perl use strict; use warnings; use Class::CSV; my $report_csv = Class::CSV->new ( fields => [qw/VM_Name VM_Cluster vFiler_IP vFiler_Cluster MisMatch/], ); $report_csv->add_line( { VM_Name => "VM1", VM_Cluster => "CLUSTER_1", vFiler_IP => "1.1.1.1", vFiler_Cluster => "CLUSTER_2", MisMatch => "What_is_that", } ); my $cvs_as_string = $report_csv->string(); my $outfile = 'final.csv'; open(my $fh, '>', $outfile) or die "Unable to open file '$outfile' for writing: $!"; print $fh $cvs_as_string; close($fh) or die "Unable to close file '$outfile': $!";