You've got the regex backwards - the text should be on the left and the pattern ('Plumbing') should be on the right: $str[1] =~ /$hash{$sic}{BUS}/;
index may be a faster alternative if you're looking for simple strings. See the examples below.
Output:use strict; use warnings; my $substr = 'Plumbing'; my $string = 'ABC Plumbing'; my $pos = index( $string, $substr ); if( $pos ) { print "Found [$substr] in [$string] at $pos\n"; } else { print "[$substr] was not found in [$string]\n"; } if( $string =~ m/$substr/ ) { print "Matched [$substr] in [$string]\n"; } else { print "[$substr] was not found in [$string]\n"; }
Found [Plumbing] in [ABC Plumbing] at 4 Matched [Plumbing] in [ABC Plumbing]
In reply to Re: searching a scalar for a word. Should I use grep?
by bobf
in thread searching a scalar for a word. Should I use grep?
by kevyt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |