Print to new file for each results



I am tring to use part of someones elses code that creates a data file which prints
out like this:

ip|result|deptA|data
ip|result|deptB|data
ip|result|deptC|data

My goal instead of having all the data in one big file is to loop this and create
a file for each result.

So I would have a deptA.out file with deptA info then a deptB.out
file with dept b info and etc.

This is not exactly doing what I need:

#!/usr/bin/perl
use strict;

my %dept = ();

while (<DATA>)
{

chomp $_;
next if ($_ eq "");

my @lines = split(/[|]/);

#$line[3] = %dept++;

$dept{$lines[2]}++;

$dept{$lines} = $value;



#print "$line";
#foreach $line (@lines) {
#print $line."\n";
#}

}

#print "@{[ %dept ]}\n";
#print "%dept";

my @array=keys(%dept);
print "All of the elements stored in %dept are @array \n";


#
__DATA__
ip|result|deptA|data
ip|result|deptB|data
ip|result|deptC|data




How would I create a file for each hash then print to it??? Any help, thanks.


Thanks,
Ron

.