#!/usr/bin/perl use strict; use warnings; # Test cases: my @strings = ("Joe Dolly", # It should split and print JD. "perl.pl", # It should match on the regular expression and nothing prints. "States"); # It should match on the regular expression and nothing prints. for my $str (@strings) { next unless $str =~ /\s/; my $out = join '', map { $_ = substr ($_, 0, 1) } split (/\s/, $str); print "$out\n"; };