$pattern = qr/^(\w*)/; if ($line =~ /$pattern/) { my $id = $1; $I++; print "$i: $id \n"; }