#! usr/bin/perl use strict; use warnings; my $search_term = 'Smith'; #no need to open the DATA handle, you can simply start reading it... for my $line (){ print $line if $line =~ m{$search_term} ; } __DATA__ Fred Smith Jane smith Bob Smitters Joe Smith __END__ This is the output I'm getting: C:\Temp>perl test.pl Fred Smith Joe Smith But I was expecting: Fred Smith Jane smith Joe Smith