#!/usr/bin/perl -w use strict; #Run the script like, tail -n +2 car.csv | ./foo.pl #I want to ignore the header my $make; #Car Make my $model; #Car Model my $out_dir="/var/tmp/cars"; #Output directory for while (<>) { ($make,$model) = split(/,/,$_,4); system("mkdir -p $out_dir/$make"); open FILE, ">>$out_dir/$make/$model" or die $!; print FILE $_; close FILE; }