Task1
We join first character of each string and check if it is equal to the given word:
#!/usr/bin/env perl
use strict;
use warnings;
sub acronyms {
(join '',map{substr $_,0,1} @{$_[0]}) eq $_[1];
}
printf"%d\n",acronyms(['Perl','Weekly','Challenge'],'PWC');
printf"%d\n",acronyms(['Bob','Charlie','Joe'],'BCJ');
printf"%d\n",acronyms(['Morning','Good'],'MM');
Task2
We can make two sets from the strings or sort the strings and check if they are equal, both methods work:
#!/usr/bin/env perl
use strict;
use warnings;
sub friendly_strings {
(join '',sort split '',$_[0]) eq (join '',sort split '',$_[1])
}
printf "%d\n",friendly_strings('desc','dsec');
printf "%d\n",friendly_strings('fuck','fcuk');
printf "%d\n",friendly_strings('poo','eop');
printf "%d\n",friendly_strings('stripe','sprite');