$one = substr($in, 23, 15); $two = substr($in, 28, 10); #### $ perl -we'sub foo { print $_[0] } eval { foo(substr "abc", 4, 1); 1} or die "croak: $@"' croak: substr outside of string at -e line 1. #### $in =~ /^ (?=.{23}(.{15})) # field one (?=.{28}(.{10})) # field two /xs or warn "bad input: $in ";