#! /usr/bin/perl use strict; use warnings; use 5.010; my $file = "/etc/hosts"; open my $rh, '<', $file or die "open($file,ro) failed: $!"; my @array = grep { m/ime\d\d\d/ } <$rh>; close $rh; # optionally, remove Newlines from matches chomp @array; # check result say join "\n", @array;