#! /usr/bin/perl # vim:ts=4 sw=4 sts=4 et nu fdc=3: use strict; use warnings; use Tie::IxHash; # keep hash sorted; see perldoc Tie::IxHash tie my %part, 'Tie::IxHash'; # read data while ( my $line = ) { # split each number into a base (variable length) # and a "postfix" which is the last digit of the number my ( $base, $postfix ) = $line =~ m/(\d+?)(\d)$/; # store the data in an HoA; see perldoc perldsc push @{ $part{$base} }, $postfix; } # create output for my $base ( keys %part ) { my @array = @{ $part{$base} }; # if we have ten postfixes for the base, # just print the base; we do NOT care if # all postfixes are different or not. if ( 10 == @array ) { print $base, $/; } else { print $base.$_.$/ for @array; } } __DATA__ 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 2343 2344 345670 345671 345672 345673 345674 345675 345676 345677 345678 345679 45 46