#!/usr/bin/perl use strict; use warnings; use feature 'say'; say "\nReady to play the anagram game? Excellent.\n\nType your first word or phrase, then hit Enter.\n\n"; chomp (my $aWord = ); say "\n\nThanks! Now type your second word or phrase and hit Enter.\n\n"; chomp (my $bWord = ); say "You typed the same word or phrase twice" and exit if $aWord eq $bWord; say is_anagram($aWord, $bWord) ? "True" : "False"; sub is_anagram { s/^ +| +$//g for @_; # remove leading or trailing spaces return 0 if length $_[0] != length $_[1]; # words are not anagrams if not the same length my @words = map {join '', sort split //, lc} @_; return $words[0] eq $words[1]; }