#!/usr/bin/perl use strict; use warnings; my %hash; while (my $row = ) { chomp $row; my @arr = split /#/, $row; $hash{$arr[1]}->{$arr[0]}=$arr[2]; } for my $key (sort keys %hash) { if ($hash{$key}->{'EE'} and $hash{$key}->{'EF'}) { print $hash{$key}->{'EF'} . "\n"; } } __DATA__ EE#123#Test1#Hallo EE#124#Test2#Hallo EE#124#Test3#Hallo EF#123#11#Hallo EF#124#12#Hallo EF#125#13#Hallo