#!/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!