#!/usr/bin/perl use strict; use warnings; my $dictionary = 'words.txt'; open(my $fh, '<', $dictionary) or die "Unable to open '$dictionary' for reading: $!"; my %data; while (<$fh>) { chomp $_; my $str = join '', sort map lc(), split //; push @{$data{$str}}, $str; } my $letters = $ARGV[0] or die "Usage: $0 "; $letters = join '', sort map lc(), split //, $letters; if (! exists $data{$letters}) { print "Could not find any matching words\n"; } else { for my $word (@{$data{$letters}}) { print "$word\n"; } }