#!/usr/bin/perl use strict; my %hash; while( ) { next if ( /^>/ ); $hash{$1} .= $2 if ( /(\d\.\d+)\s+#\s+(.*)/ ); } foreach my $i (sort keys %hash) { print "$i # $hash{$i} \n"; }