in reply to If statement not working

I'd use a hash to manage the colour/replacement pairs. Consider:

use strict; use warnings; my %colours = ( 'baby blue' => 'BB', 'baby pink' => 'BP', 'dark blue' => 'DB', 'dark purple' => 'DP', 'hot pink' => 'HP', 'light purple' => 'LP', 'pink' => 'PK', 'pinkish' => 'PI', ); my $colourMatch = join '|', sort {length $b <=> length $a || $a cmp $b} keys %colours; for my $colour ('baby blue', 'baby pink', 'baby green', 'pink', 'pinki +sh') { if ($colour =~ /($colourMatch)/) { print "Matched $colour: $colours{$1}\n"; } else { print "Unmatched: $colour\n"; } }

Prints:

Matched baby blue: BB Matched baby pink: BP Unmatched: baby green Matched pink: PK Matched pinkish: PI

Note that the sort is there so that pinkish is matched correctly rather then being matched by 'pink'. Depending on the order of your tests and the strings being tested you current code would suffer from the same problem.

True laziness is hard work