programming-examples/perl/String/Using index function to check out if a string contains a sub string.pl

19 lines
350 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
#! /usr/bin/perl -w
use strict;
print "Enter a string: ";
chomp(my $string = <STDIN>);
print "Enter a substring: ";
chomp(my $substring = <STDIN>);
my $result = index($string, $substring);
if ($result != -1) {
print "the substring was found at index: $result\n";
} else {
print "the substring was not found\n";
}