in reply to Grouping unique lines into a file.

Anonymous Monk,
If I have understood what you are trying to do, it boils down to these requirements:

Assuming the above is correct, here is how I would do it:

#!/usr/bin/perl use strict; use warnings; my %seen; while (<DATA>) { chomp; my ($acct, $data) = $_ =~ m{^(\d\d)(.*)}; next if $seen{$acct}{$data}++; append_data($acct, $_); } # If you know you are not going to exceed the open filehandle limit # You can improve performance by caching filehandles sub append_data { my ($acct, $line) = @_; open(my $fh, '>>', "$acct.txt") or die "Unable to open '$acct.txt' + for appending: $!\n"; print $fh $line; }
Here is how it would look if you know you will be safe caching file handles.
#!/usr/bin/perl use strict; use warnings; my (%seen, %fh); while (<DATA>) { chomp; my ($acct, $data) = $_ =~ m{^(\d\d)(.*)}; next if $seen{$acct}{$data}++; append_data($acct, $_, \%fh); } # Improved performance by caching filehandles sub append_data { my ($acct, $line, $fh) = @_; if (! $fh->{$acct}) { open($fh->{$acct}, '>>', "$acct.txt") or die "Unable to open ' +$acct.txt' for appending: $!\n"; } print { $fh->{$acct} } $line; }

Cheers - L~R