foreach my $i (@n) { # strip any white space $i =~ s/\s//gm; # is the /m multi-line needed? # this checks for beginning with 16 digits, plus a matching string. # this will not match unless both the digits, and the string (plus 30 chars on each end) # are in your string. $i =~ s/^(\d{16}).*?(.{30}Some search tring.{30})/$1$2/gm; # again, is the /m needed? } #### perldoc perlrequick perldoc perlretut