#!/usr/bin/perl use strict; use warnings; my $file = '/path/to/file.txt'; open(my $fh,"<",$file) or die $!; while(my $line = <$fh>){ if($line =~ /Called-Station-Id/){ my $userid = (split(/\s+/,$line))[1]; print $userid; } } close $fh;