use strict; use warnings; use v5.14; use autodie; my %word_sets; while( <> ) { chomp; my ( $conjugation, $infinitive ) = split /\s*\|\s*/; push @{ $word_sets{ $infinitive }, $conjugation; } open my $outfh, '>', 'combined_conjugations.txt'; while( my( $infinitive, $conjugations ) = each %word_sets ) { next unless @{$conjugations} > 1; # Skip items that didn't appear twice. say $outfh join( ' | ', $infinitive, @{ $conjugations } ); } close $outfh;