in reply to grep beginning of string

Hello IB2017,

As fellow Monk haukex said, if the string that you want to compare have the same root e.g. NN or NNS (same root NN) then you can use:

#!/usr/bin/perl use strict; use warnings; sub check { return substr($_[0], 0, length($_[1])) eq $_[1]; } foreach my $string ("ABC", "NXY", "NNF", "NNSX") { print "$string: ", check($string, "NN") ? "yes!\n" : "no\n"; } __END__ $ perl test.pl ABC: no NXY: no NNF: yes! NNSX: yes!

Should be faster than grep you can Benchmark the codes.

Update: Removing unnecessary sample of code.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!