#!/usr/bin/perl -w use strict; my $ex_line = q(perl -ne "if (/(\d{6})_/g){ chomp;print qq($1,),(split/;/,$_)[-1],qq(\n)};" input.dat); my $stuff = `$ex_line`; my %hash; for (split /\n/, $stuff) { my @arr = split/,/,$_; push @{$hash{$arr[0]}} , $arr[1]; } foreach (keys %hash) { print "$_\t" . join / /, @{$hash{$_}} , qq(\n); } 1;