use strict; use warnings; print "Enter a string: "; chomp ($_ = <>); my $msg = !/a/i ? 'String did not match' : !/a.*b/i ? 'The string has an a, but not a following b' : 'The string has an a, but also a following b' ; print $msg, "\n";