#!/usr/local/bin/perl use strict; use warnings; my $match=0; my $string = "do you know my name is Simon\n I have a clock on my wall"; while(){ if($string=~ /\bclock\b/s){ $match++; last; }else{last;} } $match ? print "Found Pattern!\n":print "did not find pattern!\n";