#!/usr/bin/perl use warnings; use strict; my @array = qw( testme ); my $string = qq! first ! . ( grep /testme/, @array ? qq! yes ! : qq! no ! ) . qq! end !; print $string;