#!/usr/bin/perl use warnings; use strict; # use ARGV's magic @ARGV = "test.txt"; my @results; while ( ){ chomp $_; if ($_ =~ m/head/){ push (@results, $_); } } print "@results\n";