#!/usr/bin/perl use strict; use warnings; my @array = qw( xx1111y000 xx1111y001 xx1111y002 xx2222y000 xx2222y001 ); my %hash; for my $element ( @array ) { if ( $element =~ m/(\w{6})(\w{4})/ ) { # fuelle Hash-of-Array push @{ $hash{$1} }, $2; } } for my $key ( sort keys %hash ) { # dereferenziere Hash-of-Array und baue String zusammen my $value = join ', ', @{ $hash{$key} }; print qq{