use warnings; use strict; use IPC::System::Simple qw/capturex/; my @cmd = ('cat', 'sample.txt'); # just an example print map { s/^_id://; $_ } grep { /^_id:/ } capturex(@cmd);