#!/usr/bin/env perl use strict; use warnings; print /(error.*)/ ? $1 : '' for ; __DATA__ foo error bar baz