#!/usr/bin/perl -w use strict; my @input =`ipcs`; @input = grep (/$ARGV[0]/, @input); foreach my $line (@input) { my @entry = split (/\s+/, $line); my $test = `ipcrm sem $entry[1]` if (scalar(@entry) == 5); $test = `ipcrm shm $entry[1]` if (scalar(@entry) == 6); print "Result for id $entry[1]: $test" if $test; }