#! /usr/bin/perl -lw # use strict ; my $key = "b" ; printf "key=%s, value is %s\n", $key, get_value($key) ; sub get_value { my $key = shift ; my @ta = ("a x", "b y", "c z") ; # test array return (map{ /^$key/ and s/^$key//, $_ } grep( /^$key/, @ta))[1] ; }