#!/usr/bin/perl -- use strict; use warnings; sub mapAdj(&$@) { use vars qw/ $a $b $c $d $e $f $g $h $i $j /; local( $a, $b, $c, $d, $e, $f, $g, $h, $i, $j ); my( $code, $n ) = ( shift, shift ); map $code->( ($a, $b, $c, $d, $e, $f, $g, $h, $i, $j ) = @_[ $_-$n .. $_ ] ), --$n .. $#_; } sub subsumes { return 0 == index $_[1], $_[0]; } my $termies = " a/ a/b/ a/b/t/ a/b/t/f a/c/ a/c/d/ a/c/d/t/ a/c/d/t/f t/ "; open my($fh),'<',\$termies; my @terminals; while(<$fh>){ chomp; push @terminals, $_ if m{/\s*$}sm; } @terminals = mapAdj { subsumes($a,$b) ? ( ) : ( $a ) } 2, (sort @terminals), ''; print "$_\n" for @terminals; __END__ a/b/t/ a/c/d/t/ t/