use strict; use warnings; my @words = (); my @cvs = (); # push some hash data onto the arrays, in real life this would be # huge files with phonetical transcripton, not VC toilets push @cvs, { file => 1, text => 'v' }; push @cvs, { file => 1, text => 'c' }; push @cvs, { file => 1, text => 'c' }; push @cvs, { file => 2, text => 'c' }; push @cvs, { file => 2, text => 'v' }; push @cvs, { file => 2, text => 'c' }; push @cvs, { file => 2, text => 'c' }; push @words, { file => 1, text => 'üks' }; push @words, { file => 2, text => 'kaks' }; my $cv_as_text; my @cvs_to_delete = (); # for each word we have to find its consistents for my $w_i (0 .. $#words) { my %word = %{$words[$w_i]}; my $cv_as_text = ''; my @cvs_to_delete = (); print "$w_i: $word{text}\n "; # now loop through the consistents and find correct match for my $c_i (0 .. $#cvs) { my %cv = %{$cvs[$c_i]}; # in real life this is done with micro seconds, not file nr if( $cv{file} == $word{file}) { $cv_as_text .= $cv{text}; push @cvs_to_delete, $c_i; print $cv{text}; } # we don't want to search to the end (data is ordered) elsif ($cv{file} > $word{file}) { last; } } print "\n"; # now delete all cvs we extracted @cvs_to_delete = reverse sort @cvs_to_delete; for my $del (@cvs_to_delete) { splice (@cvs, $del, 1); } }