my @bintext2 = grep { $_ =~ /$input/i } @bintext; # or even shorter my @bintext2 = grep { /$input/i } @bintext;