#!/usr/bin/perl use strict; use warnings; # Get the filename as command line argument my $filename = shift; open my $fh, "<", $filename or die "Can't open $filename"; while ( my $line = <$fh> ) { # go through file, line by line my @fields = split ':', $line; my ($first) = split /\s+/, $fields[4]; print "$first\n"; } close $fh;