#!perl -lp BEGIN { $s = shift } sub cut { my ($s, $r) = pop; for (split /,/, shift) { $r .= /(\d+)-(\d+)/ ? substr $s,$1-1,$2-$1+1 : substr $s, $_-1,1; } $r; } chomp; $_=cut $s, $_;