use Text::CSV; my $csv = Text::CSV->new( { sep_char => ' '} ); my $fh = *DATA; # Replace *DATA with your input file name while ( my $row = $csv->getline( $fh ) ) { say join '-', @$row; } __DATA__ abc def data 123 ghi jkl "data with spaces" 456 "oh dear" "more data with spaces"