I'm not quite sure what you mean by "arbitrary string variable" and "unknown in advance", but maybe something like:
c:\@Work\Perl\monks>perl -wMstrict -le
"chomp(my $string_to_find = <STDIN>);
;;
my @array_to_search = qw(Foo whathiddenever Bar 12hidden456);
;;
for my $s (@array_to_search) {
print qq{'$s' has '$string_to_find'} if $s =~ $string_to_find;
}
"
hidden
'whathiddenever' has 'hidden'
'12hidden456' has 'hidden'
Update: In general, strings and, better yet, regex objects created by qr// (see Regexp Quote-Like Operators in perlop) can be interpolated into and thus used to compose other regex objects:
c:\@Work\Perl\monks>perl -wMstrict -le
"chomp(my $string_to_find = <STDIN>);
;;
my @array_to_search = qw(Foo whathi$denever Bar 12hi$den456);
;;
my $rx_search = qr{ (?<= \d) \Q$string_to_find\E (?= \d) }xms;
;;
for my $s (@array_to_search) {
print qq{'$s' has '$string_to_find'} if $s =~ $rx_search;
}
"
hi$den
'12hi$den456' has 'hi$den'
This illustrates both interpolation for composition and metaquoting with
\Q ... \E of an interpolated variable. See
Quote and Quote-like Operators in
perlop,
perlre.
Give a man a fish: <%-{-{-{-<