#!/usr/bin/perl use strict; use warnings; my $file = '/path/to/file.txt'; open IN, "<", $file or die "Could not open $file:$!\n"; my $wanted; while (my $line = ) { if ($line =~ /(All avg = \d+)/) { $wanted = $1; last; # get rid of this if you need/expect to match multiple lines } }