require 5.000; use warnings; use strict; use POSIX; my %tags = (); my $input = $ARGV[0]; my $output = $ARGV[1]; open (FILE, "< $input") or die "cannot open $input: $!\n"; while (my $tag = ) { $tag =~ m//; if ($tag eq "\n") { # BLANK LINE } else { $tag =~ m//; $tags{sprintf("%04d%6s",$1 || 9999,$2)} = $tag; } } close NEWFILE; close FILE; open (NEWFILE, "> $output") or die "cannot open $output: $!\n"; foreach my $id ( sort keys %tags ) { print NEWFILE $tags{$id}; print $tags{$id}; } close NEWFILE; close FILE;