#!/usr/bin/perl -n my ($file, $rec) = split /\|/, $_, 2; # Good idea, jdporter and BrowserUk unless(exists $fh{$file}) { open $fh{$file}, ">> $file" or die "Can't open $file for append: $!\n"; } $fh{$file}->print $rec;