$trimmedcolr = $colr; $trimmedcolr = 'BB' if $colr eq 'baby blue'; $trimmedcolr = 'BP' if $colr eq 'baby pink'; $trimmedcolr = 'DB' if $colr eq 'dark blue'; $trimmedcolr = 'DP' if $colr eq 'dark purple'; $trimmedcolr = 'HP' if $colr eq 'hot pink'; $trimmedcolr = 'LP' if $colr eq 'light purple'; #### #!/usr/bin/perl -w use strict; my @colors = ( 'baby blue', 'baby pink', 'dark blue', 'dark purple', 'hot pink', 'light purple', 'wild green', 'crazy yellow', 'wild crazy purple', 'deep purple'); foreach (@colors) { print getColorAbreviation($_),"\n"; } # The translation algorithm appears to be straight- # forward, so a table independent translation is # possible ... Of course 'dark purple' and 'deep purple' # would translate into the same thing, but maybe that is # ok? This is application dependent. sub getColorAbreviation { my $color = shift; #like: 'wild crazy purple' $color = uc $color; my @FirstCaps = $color =~ /(\w)\w+/g; return @FirstCaps; #like: WCP } __END__ BB BP DB DP HP LP WG CY WCP DP