#!/usr/bin/env perl use warnings; use strict; open my $fh, '<', 'foo.txt' or die "Can not open file: foo.txt: $!\n"; while (<$fh>) { if (/^\w{3};\w/) { print; # or do whatever you need to do... } } close $fh or die "Can not close file: foo.txt: $!\n";