undef $/; my $number = 42; #or $number = $ARGV[0] or whatever line number you were looking for my $file = ; my ($line, $name); # ($line) = $file =~ /$($number\s+.*)/m; # would store the whole line ($number, $name) = $file =~ /$($number)\s+(.*)/m; # use the second form since you just want number and name # and yes, you are overwriting the value of $number # with itself all over again. Use (undef, $name) = $file... # if that makes you feel more comfortable.