#!/usr/bin/perl # http://perlmonks.org/?node_id=1201500 use strict; use warnings; my $file = '/usr/share/dict/words'; # YMMV open my $fh, '<', $file or die "$! opening $file"; while(<$fh>) { /^[a-z]{6,}$/i or next; my $word = $_; my @counts; $counts[ s/$&//gi ] .= $& while s/.//; grep(!$_ || /../, @counts) or print $word; }