use strict; use warnings; # Read the entire file contents into $content my $file = 'test.txt'; open(my $fh, '<', $file) or die "$file: $!"; my $content = do { local $/; <$fh> }; close($fh); # Remove newlines and "\\n" sequences $content =~ s/\n|\\n//g; # Match strings my @matches = $content =~ m/saravanan/g; print "@matches\n";