# load file into an array of lines, and use "Line 3": my @lines = ; my ( $keeper ) = grep /^Line 3 : /, @lines; # or just get "Line 3" from the file, and skip the rest: #my ($keeper) = grep /^Line 3 : /, ; # (update: added parens around $keeper, as per Aristotle's correction) # either way, remove the unwanted content from the kept line: $keeper =~ s/Line 3 : //;