#!perl -w use strict; my $key="5 10 14 16 17 20 25 26 38 1 42 47 54"; my $substr = " 1 "; my @newarray= $key; foreach $key ( @newarray ) { if (index($key, $substr) != -1) { print "\nExist (substr)" }; if ($key =~ /\Q$substr\E/) { print "\nExist (RE)" }; if ($key =~ /\s+1\s+/) { print "\nExist (whitespace)" }; } __END__ >perl -w tmp.pl Exist (substr) Exist (RE) Exist (whitespace)