in reply to Duplicate removal

You could create a Hash-of-Arrays data structure. The hash keys could be a concatenation of the 1st 3 columns, and the hash values could be an array of all the last column values:
use strict; use warnings; my %data; while (<DATA>) { my @cols = split; my $col3 = pop @cols; my $key = "@cols"; push @{ $data{$key} }, $col3; } for (keys %data) { print "$_ ", join(',', @{ $data{$_} }), "\n"; } __DATA__ chr1 12345 34567 gene1 chr1 12345 34567 gene2

Output:

chr1 12345 34567 gene1,gene2

Replies are listed 'Best First'.
Re^2: Duplicate removal
by perl_paduan (Initiate) on Apr 07, 2010 at 16:38 UTC
    Thanks and thanks to umasuresh and toolic!
    Both codes work perfectly!!!